Read the Keyboard
Moderator: Rathinagiri
Read the Keyboard
Estoy intentando utilizar el código de srvet_claudio para usarlo en un browse con búsqueda incremental, pero no consigo que me acepte minúsculas, Ñ mayúscula y en general caracteres como ( ) ? ¿ $ etc...
Alguién sabe como corregir esto.
Por otra parte ¿ no existe algo sencillo como era Lastkey() en clipper que nos devuelva la tecla pulsada ?
Un saludo
Alguién sabe como corregir esto.
Por otra parte ¿ no existe algo sencillo como era Lastkey() en clipper que nos devuelva la tecla pulsada ?
Un saludo
- dhaine_adp
- Posts: 457
- Joined: Wed Aug 06, 2008 12:22 pm
- Location: Manila, Philippines
Re: Read the Keyboard
Hi Agustin,
Please follow this thread: viewtopic.php?f=15&t=1331&hilit=read+keyboard
Written by Dr. Claudio
Regards,
Danny
Please follow this thread: viewtopic.php?f=15&t=1331&hilit=read+keyboard
Written by Dr. Claudio
Regards,
Danny
Regards,
Danny
Manila, Philippines
Danny
Manila, Philippines
Re: Read the Keyboard
Gracias. He compilado ese ejemplo y siempre me escribe en mayúsculas , aunque en el label ponga " Escribiendo en minúsculas"
Thank you. I compiled this example and I always write in capital letters, although the label set "Writing lowercase"
Thank you. I compiled this example and I always write in capital letters, although the label set "Writing lowercase"
Re: Read the Keyboard
Podría alguien probar este ejemplo del Dr Claudio y ver si acepta letras minúsculas ?. es por si es problema de mi equipo
Gracias
Gracias
-
Leopoldo Blancas
- Posts: 388
- Joined: Wed Nov 21, 2012 7:14 pm
- Location: México
Re: Read the Keyboard
Hola Agustín...
Ya los compile y si me deja escribirlos en minúsculas....
Ya los compile y si me deja escribirlos en minúsculas....
- Attachments
-
- Keyboard.png (27.03 KiB) Viewed 4075 times
Re: Read the Keyboard
Si. Abajo escribe minúsculas, pero arriba te devuelve la D mayúscula y VK code 68 y la "d" tiene código 100. Creo que el ejemplo tiene algún problema.
Gracias por tu atención
Gracias por tu atención
Re: Read the Keyboard
Me parece que esta aportacion del Dr. Claudio es muy importante, ya que hemos perdido la utilidad de LASTKEY() y siempre es necesario el poder capturar la tecla pulsada.
En mi caso, no consigo que me funcione y por eso envio un ejemplo que uso para hacer búsquedas incrementales en un Browse.
Agradeceré cualquier ayuda
Saludos
No se porqué no puedo mandar el ajunto.
Lo pongo aquí y os pido disculpas
#include "minigui.ch"
FUNCTION MAIN
Set CodePage To Spanish
DEFINE WINDOW frmMain ;
AT 0,0 ;
WIDTH 500 ;
HEIGHT 400 ;
TITLE "VENTANA A" ;
MAIN
@ 10 , 10 LABEL Label_1 VALUE "Escribir por ejemplo : 'Base de Datos 23/45' usando para mayuscula la tecla Shift" AUTOSIZE
@ 50 , 10 LABEL Label_2 VALUE "" AUTOSIZE
INSTALL_READ_KEYBOARD ()
DEFINE TIMER timer_1 INTERVAL 700 ACTION _EvalKeyPress( ) // <== Hay que controlar el intervalo para que no repita pulsaciones
**************************************************
END WINDOW
frmMain.CENTER
frmMain.ACTIVATE
RETURN
PROCEDURE _EvalKeyPress( )
LOCAL nKeyPress := GET_LAST_VK( )
LOCAL cKeyPress := GET_LAST_VK_NAME( )
LOCAL cValor := GetProperty( "frmMain" , "Label_2" , "value" )
if cKeyPress $ "abcdefghijklmnñopqrstuvwxyzABCDEFGHIJKLMNÑOPQRSTUVWXYZ1234567890!•$%&/()=?¿*ç_-.:,;<>ºª\ "
PAUSE_READ_VK (.T.) // pausa la lectura del teclado para procesar la tecla presionada
frmMain.Timer_1.Enabled := .F.
cValor := cValor + cKeyPress
SetProperty( "frmMain" , "Label_2" , "value" , cValor )
endif
* MUY IMPORTANTE **************************************************
frmMain.Timer_1.Enabled := .T.
PAUSE_READ_VK (.F.) // restablece la lectura del teclado luego de la pausa
*******************************************************************
RETURN
*#########################################################################################################################
* FUNCIONES EN C
*#########################################################################################################################
#pragma begindump
#include <windows.h>
#include "hbapi.h"
BOOL flag_hhk = FALSE;
BOOL PAUSE_hhk = FALSE;
HHOOK hhk = NULL;
long VK_PRESIONADO = 0;
LONG VK_lParam = 0;
LRESULT CALLBACK KeyboardProc(int nCode, WPARAM wParam, LPARAM lParam)
{
if (nCode < 0)
return CallNextHookEx(hhk, nCode, wParam, lParam);
if (PAUSE_hhk == FALSE)
{ VK_PRESIONADO = (long) wParam;
VK_lParam = (LONG) lParam;
}
else
{ VK_PRESIONADO = 0;
VK_lParam = 0;
}
return CallNextHookEx(hhk, nCode, wParam, lParam);
}
HB_FUNC (GET_STATE_VK_SHIFT)
{
if (GetKeyState(VK_SHIFT) & 0x8000)
hb_retl (TRUE);
else
hb_retl (FALSE);
}
HB_FUNC (GET_STATE_VK_CONTROL)
{
if (GetKeyState(VK_CONTROL) & 0x8000)
hb_retl (TRUE);
else
hb_retl (FALSE);
}
HB_FUNC (GET_STATE_VK_ALT)
{
if (GetKeyState(VK_MENU) & 0x8000)
hb_retl (TRUE);
else
hb_retl (FALSE);
}
HB_FUNC (GET_LAST_VK)
{ if (flag_hhk == TRUE)
hb_retnl (VK_PRESIONADO);
else
hb_retnl (0);
}
HB_FUNC (GET_LAST_VK_NAME)
{ CHAR cadena [128];
if (flag_hhk == TRUE)
{ GetKeyNameText (VK_lParam, (LPTSTR) &cadena, 128);
hb_retc (cadena);
}
else
hb_retc ("");
}
HB_FUNC (PAUSE_READ_VK)
{ if (hb_pcount () == 1 && hb_parinfo (1) == HB_IT_LOGICAL)
{ if (hb_parl (1) == TRUE)
{ VK_PRESIONADO = 0;
VK_lParam = 0;
}
PAUSE_hhk = hb_parl (1);
}
}
HB_FUNC (INSTALL_READ_KEYBOARD)
{ if (flag_hhk == FALSE)
{ hhk = SetWindowsHookEx (WH_KEYBOARD, KeyboardProc, (HINSTANCE) NULL, GetCurrentThreadId());
if (hhk == NULL)
hb_retl (FALSE);
else
{ flag_hhk = TRUE;
hb_retl (TRUE);
}
}
else
hb_retl (TRUE);
}
HB_FUNC (UNINSTALL_READ_KEYBOARD)
{ if (flag_hhk == TRUE)
{ if (UnhookWindowsHookEx (hhk) == TRUE)
{ flag_hhk = FALSE;
hb_retl (TRUE);
}
else
hb_retl (FALSE);
}
else
hb_retl (TRUE);
}
#pragma enddump
En mi caso, no consigo que me funcione y por eso envio un ejemplo que uso para hacer búsquedas incrementales en un Browse.
Agradeceré cualquier ayuda
Saludos
No se porqué no puedo mandar el ajunto.
Lo pongo aquí y os pido disculpas
#include "minigui.ch"
FUNCTION MAIN
Set CodePage To Spanish
DEFINE WINDOW frmMain ;
AT 0,0 ;
WIDTH 500 ;
HEIGHT 400 ;
TITLE "VENTANA A" ;
MAIN
@ 10 , 10 LABEL Label_1 VALUE "Escribir por ejemplo : 'Base de Datos 23/45' usando para mayuscula la tecla Shift" AUTOSIZE
@ 50 , 10 LABEL Label_2 VALUE "" AUTOSIZE
INSTALL_READ_KEYBOARD ()
DEFINE TIMER timer_1 INTERVAL 700 ACTION _EvalKeyPress( ) // <== Hay que controlar el intervalo para que no repita pulsaciones
**************************************************
END WINDOW
frmMain.CENTER
frmMain.ACTIVATE
RETURN
PROCEDURE _EvalKeyPress( )
LOCAL nKeyPress := GET_LAST_VK( )
LOCAL cKeyPress := GET_LAST_VK_NAME( )
LOCAL cValor := GetProperty( "frmMain" , "Label_2" , "value" )
if cKeyPress $ "abcdefghijklmnñopqrstuvwxyzABCDEFGHIJKLMNÑOPQRSTUVWXYZ1234567890!•$%&/()=?¿*ç_-.:,;<>ºª\ "
PAUSE_READ_VK (.T.) // pausa la lectura del teclado para procesar la tecla presionada
frmMain.Timer_1.Enabled := .F.
cValor := cValor + cKeyPress
SetProperty( "frmMain" , "Label_2" , "value" , cValor )
endif
* MUY IMPORTANTE **************************************************
frmMain.Timer_1.Enabled := .T.
PAUSE_READ_VK (.F.) // restablece la lectura del teclado luego de la pausa
*******************************************************************
RETURN
*#########################################################################################################################
* FUNCIONES EN C
*#########################################################################################################################
#pragma begindump
#include <windows.h>
#include "hbapi.h"
BOOL flag_hhk = FALSE;
BOOL PAUSE_hhk = FALSE;
HHOOK hhk = NULL;
long VK_PRESIONADO = 0;
LONG VK_lParam = 0;
LRESULT CALLBACK KeyboardProc(int nCode, WPARAM wParam, LPARAM lParam)
{
if (nCode < 0)
return CallNextHookEx(hhk, nCode, wParam, lParam);
if (PAUSE_hhk == FALSE)
{ VK_PRESIONADO = (long) wParam;
VK_lParam = (LONG) lParam;
}
else
{ VK_PRESIONADO = 0;
VK_lParam = 0;
}
return CallNextHookEx(hhk, nCode, wParam, lParam);
}
HB_FUNC (GET_STATE_VK_SHIFT)
{
if (GetKeyState(VK_SHIFT) & 0x8000)
hb_retl (TRUE);
else
hb_retl (FALSE);
}
HB_FUNC (GET_STATE_VK_CONTROL)
{
if (GetKeyState(VK_CONTROL) & 0x8000)
hb_retl (TRUE);
else
hb_retl (FALSE);
}
HB_FUNC (GET_STATE_VK_ALT)
{
if (GetKeyState(VK_MENU) & 0x8000)
hb_retl (TRUE);
else
hb_retl (FALSE);
}
HB_FUNC (GET_LAST_VK)
{ if (flag_hhk == TRUE)
hb_retnl (VK_PRESIONADO);
else
hb_retnl (0);
}
HB_FUNC (GET_LAST_VK_NAME)
{ CHAR cadena [128];
if (flag_hhk == TRUE)
{ GetKeyNameText (VK_lParam, (LPTSTR) &cadena, 128);
hb_retc (cadena);
}
else
hb_retc ("");
}
HB_FUNC (PAUSE_READ_VK)
{ if (hb_pcount () == 1 && hb_parinfo (1) == HB_IT_LOGICAL)
{ if (hb_parl (1) == TRUE)
{ VK_PRESIONADO = 0;
VK_lParam = 0;
}
PAUSE_hhk = hb_parl (1);
}
}
HB_FUNC (INSTALL_READ_KEYBOARD)
{ if (flag_hhk == FALSE)
{ hhk = SetWindowsHookEx (WH_KEYBOARD, KeyboardProc, (HINSTANCE) NULL, GetCurrentThreadId());
if (hhk == NULL)
hb_retl (FALSE);
else
{ flag_hhk = TRUE;
hb_retl (TRUE);
}
}
else
hb_retl (TRUE);
}
HB_FUNC (UNINSTALL_READ_KEYBOARD)
{ if (flag_hhk == TRUE)
{ if (UnhookWindowsHookEx (hhk) == TRUE)
{ flag_hhk = FALSE;
hb_retl (TRUE);
}
else
hb_retl (FALSE);
}
else
hb_retl (TRUE);
}
#pragma enddump
- Pablo César
- Posts: 4059
- Joined: Wed Sep 08, 2010 1:18 pm
- Location: Curitiba - Brasil
Read the Keyboard
Fiajte si así te resuelve:
Coloqué la variable cValor como Private e adicioné un EditBox. Tu puedes colocarlo invisible. Todo sea para que puedas comparar con lo que está teclando e los timers.
Sobre las minúsculas hice una transformacion de mayusculas para minusculas caso CapsLock o Shift estén accendidos.
Si irá trabajar con la version UNICODE, tendrás que substituir las funcciones de retorno de hb_ para hmg_. Ver con el Dr. Soto.
En el código C, intenté colocar el fflush(stdin); de #include <stdio.h> para vaciar el keyboard buffer, pero no consegui con éxito.
Code: Select all
#include "hmg.ch"
Function Main
Set CodePage To Spanish
Private cValor:=""
DEFINE WINDOW frmMain ;
AT 0,0 ;
WIDTH 500 ;
HEIGHT 400 ;
TITLE "VENTANA A" ;
MAIN
@ 10 , 10 LABEL Label_1 VALUE "Escribir por ejemplo : 'Base de Datos 23/45' usando para mayuscula la tecla Shift" AUTOSIZE
@ 50 , 10 LABEL Label_2 VALUE "" AUTOSIZE
DEFINE EDITBOX Edit_1
ROW 100
COL 210
WIDTH 120
HEIGHT 120
VALUE ""
FONTNAME "Arial"
FONTSIZE 9
TOOLTIP ""
ONCHANGE Nil
ONGOTFOCUS Nil
ONLOSTFOCUS Nil
FONTBOLD .F.
FONTITALIC .F.
FONTUNDERLINE .F.
FONTSTRIKEOUT .F.
HELPID Nil
TABSTOP .T.
VISIBLE .T.
READONLY .F.
HSCROLLBAR .T.
VSCROLLBAR .T.
DISABLEDBACKCOLOR Nil
DISABLEDFONTCOLOR Nil
BACKCOLOR Nil
FONTCOLOR Nil
END EDITBOX
INSTALL_READ_KEYBOARD ()
DEFINE TIMER timer_1 OF frmMain INTERVAL 100 ACTION _EvalKeyPress() // <== Hay que controlar el intervalo para que no repita pulsaciones
END WINDOW
frmMain.CENTER
frmMain.ACTIVATE
RETURN Nil
Function _EvalKeyPress()
Local cKeyPress := GET_LAST_VK_NAME()
Local cString := GetProperty( "frmMain" , "Edit_1" , "Value" )
If !((GET_STATE_VK_SHIFT()=.T. .OR. IsCapsLockActive() =.T.) .AND. GET_LAST_VK() <> 0)
cKeyPress := Lower(cKeyPress)
Endif
If cKeyPress $ "abcdefghijklmnñopqrstuvwxyzABCDEFGHIJKLMNÑOPQRSTUVWXYZ1234567890!•$%&/()=?¿*ç_-.:,;<>ºª\ "
PAUSE_READ_VK (.T.) // pausa la lectura del teclado para procesar la tecla presionada
frmMain.Timer_1.Enabled := .F.
If !(Len(cValor)==Len(cString))
cValor := cValor + cKeyPress
Endif
SetProperty( "frmMain" , "Label_2" , "value" , cValor )
SetProperty( "frmMain" , "Edit_1" , "SetFocus")
frmMain.Timer_1.Enabled := .T.
PAUSE_READ_VK (.F.) // restablece la lectura del teclado luego de la pausa
Endif
RETURN nil
*#########################################################################################################################
* FUNCIONES EN C
*#########################################################################################################################
#pragma begindump
#include <windows.h>
#include "hbapi.h"
#include <stdio.h>
BOOL flag_hhk = FALSE;
BOOL PAUSE_hhk = FALSE;
HHOOK hhk = NULL;
long VK_PRESIONADO = 0;
LONG VK_lParam = 0;
LRESULT CALLBACK KeyboardProc(int nCode, WPARAM wParam, LPARAM lParam)
{
if (nCode < 0)
return CallNextHookEx(hhk, nCode, wParam, lParam);
if (PAUSE_hhk == FALSE)
{ VK_PRESIONADO = (long) wParam;
VK_lParam = (LONG) lParam;
}
else
{ VK_PRESIONADO = 0;
VK_lParam = 0;
}
return CallNextHookEx(hhk, nCode, wParam, lParam);
}
HB_FUNC (GET_STATE_VK_SHIFT)
{
if (GetKeyState(VK_SHIFT) & 0x8000)
hb_retl (TRUE);
else
hb_retl (FALSE);
}
HB_FUNC (GET_STATE_VK_CONTROL)
{
if (GetKeyState(VK_CONTROL) & 0x8000)
hb_retl (TRUE);
else
hb_retl (FALSE);
}
HB_FUNC (GET_STATE_VK_ALT)
{
if (GetKeyState(VK_MENU) & 0x8000)
hb_retl (TRUE);
else
hb_retl (FALSE);
}
HB_FUNC (GET_LAST_VK)
{ if (flag_hhk == TRUE)
hb_retnl (VK_PRESIONADO);
else
hb_retnl (0);
}
HB_FUNC (GET_LAST_VK_NAME)
{ CHAR cadena [128];
if (flag_hhk == TRUE)
{ GetKeyNameText (VK_lParam, (LPTSTR) &cadena, 128);
hb_retc (cadena);
}
else
hb_retc ("");
}
HB_FUNC (PAUSE_READ_VK)
{ if (hb_pcount () == 1 && hb_parinfo (1) == HB_IT_LOGICAL)
{ if (hb_parl (1) == TRUE)
{ VK_PRESIONADO = 0;
VK_lParam = 0;
}
PAUSE_hhk = hb_parl (1);
}
}
HB_FUNC (INSTALL_READ_KEYBOARD)
{ if (flag_hhk == FALSE)
{ hhk = SetWindowsHookEx (WH_KEYBOARD, KeyboardProc, (HINSTANCE) NULL, GetCurrentThreadId());
if (hhk == NULL)
hb_retl (FALSE);
else
{ flag_hhk = TRUE;
hb_retl (TRUE);
}
}
else
hb_retl (TRUE);
}
HB_FUNC (UNINSTALL_READ_KEYBOARD)
{ if (flag_hhk == TRUE)
{ if (UnhookWindowsHookEx (hhk) == TRUE)
{ flag_hhk = FALSE;
hb_retl (TRUE);
}
else
hb_retl (FALSE);
}
else
hb_retl (TRUE);
}
#pragma enddumpSobre las minúsculas hice una transformacion de mayusculas para minusculas caso CapsLock o Shift estén accendidos.
Si irá trabajar con la version UNICODE, tendrás que substituir las funcciones de retorno de hb_ para hmg_. Ver con el Dr. Soto.
En el código C, intenté colocar el fflush(stdin); de #include <stdio.h> para vaciar el keyboard buffer, pero no consegui con éxito.
HMGing a better world
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein
Re: Read the Keyboard
Gracias por tu ayuda Pablo Cesar. Lo voy a probar y lo comento.
Saludos cordiales
Saludos cordiales
- Pablo César
- Posts: 4059
- Joined: Wed Sep 08, 2010 1:18 pm
- Location: Curitiba - Brasil
Read the Keyboard
Creo que para la digitación de la letra ñ o Ñ (eñe) tendrás que hacer una rotina para esperar la segunda tecla después de la "~". O talvez precise normalizar el codepage con respecto a UNICODE (en las funcion del código y en los dbfs). UNICODE, sin duda alguna, es el mejor camino para obter e compatibilizar resultados de diferentes lenguajes.
El código que te pasé, está funcionando. No acostumbro pasar nada sin testearlo antes...
El código que te pasé, está funcionando. No acostumbro pasar nada sin testearlo antes...
HMGing a better world
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein