Read the Keyboard

HMG en Español

Moderator: Rathinagiri

User avatar
esgici
Posts: 4543
Joined: Wed Jul 30, 2008 9:17 pm
DBs Used: DBF
Location: iskenderun / Turkiye
Contact:

Re: Read the Keyboard

Post by esgici »

Congrats amigo ;)

Happy HMG'in :D ( for ALL )

Cordialmente
Viva INTERNATIONAL HMG :D
User avatar
srvet_claudio
Posts: 2220
Joined: Thu Feb 25, 2010 8:43 pm
Location: Uruguay
Contact:

Re: Read the Keyboard

Post by srvet_claudio »

Agustin wrote: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
Agustin, el problema surge porque esta rutina esta desarrollada para correr con aplicaciones en ANSI, voy a desarrollar una para Unicode.
Saludos,
Claudio.
Best regards.
Dr. Claudio Soto
(from Uruguay)
http://srvet.blogspot.com
Agustin
Posts: 79
Joined: Sat Feb 16, 2013 10:50 pm
Location: Miranda de Ebro / España

Re: Read the Keyboard

Post by Agustin »

Gracias Claudio. Será una gran aportación para HMG.

Saludos
User avatar
Pablo César
Posts: 4059
Joined: Wed Sep 08, 2010 1:18 pm
Location: Curitiba - Brasil

Re: Read the Keyboard

Post by Pablo César »

Pablo César wrote:Si irá trabajar con la version UNICODE, tendrás que substituir las funcciones de retorno de hb_ para hmg_. Ver con el Dr. Soto.
Sim
HMGing a better world
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein
Post Reply