In this code I have the number virtual key. I need the asc code.
- Code: Select all Expand view
#include "fivewin.ch"
Function TestHook()
Local nKey
Local oWnd
Private oTimer
DEFINE WINDOW oWnd TITLE "3D objects"
ACTIVATE WINDOW oWnd On Init (MyHook(oWnd))
IF UNINSTALL_READ_KEYBOARD() == .F.
? "ERROR al desinstalar READ_KEYBOARD"
ENDIF
Return
Static Function MyHook(oWnd)
IF INSTALL_READ_KEYBOARD() == .F.
? 'ERROR al instalar READ_KEYBOARD'
Return
EndIf
DEFINE TIMER oTimer OF oWnd INTERVAL 100 ACTION Processar_Tecla()
oTimer:Activate()
Return
Static Function Processar_Tecla()
Local nKey := GET_LAST_VK(1)
Local nChar
Static nKeyAnt := 0
oTimer:DeActivate()
If nKey # nKeyAnt
nKeyAnt := nKey
nChar := GET_LAST_VK(3)
MsgStop(Str(nKey,6)+" "+Str(GET_LAST_VK(2),10)+" "+Str(GET_LAST_VK(3),6)+" "+Str(GET_LAST_VK(4),6))
EndIf
oTimer:Activate()
Return
*##################################################################################################
* FUNCIONES EN C
*##################################################################################################
#pragma begindump
#include <windows.h>
#include <stdlib.h>
#include "hbapi.h"
#define WH_KEYBOARD_LL 13
HINSTANCE hInst ; // Instance handle
HB_BOOL flag_hhk = FALSE;
HHOOK hhk = NULL;
HB_LONG VK_PRESIONADO = 0;
HB_LONG VK_lParam = 0;
HB_LONG VK_Code = 0;
LRESULT CALLBACK KeyboardProc(int nCode, WPARAM wParam, LPARAM lParam)
{
if (nCode < 0)
return CallNextHookEx(hhk, nCode, wParam, lParam);
VK_Code = (LONG) nCode;
VK_PRESIONADO = (long) wParam;
VK_lParam = (LONG) lParam;
return CallNextHookEx(hhk, nCode, wParam, lParam);
}
HB_FUNC (GET_LAST_VK)
{
int iPCount;
int iAscCod;
iAscCod = 65 // It's here I need to convert.
iPCount = hb_pcount();
if (iPCount == 0)
hb_retnl(VK_PRESIONADO);
else if (hb_parni(1) == 1)
hb_retnl(VK_PRESIONADO);
else if (hb_parni(1) == 2)
hb_retnl(VK_lParam);
else if (hb_parni(1) == 3)
hb_retnl(VK_Code);
else if (hb_parni(1) == 4)
hb_retnl(iAscCod);
}
HB_FUNC (GET_LAST_VK_NAME)
{
CHAR cadena [128];
GetKeyNameText (VK_lParam, (LPTSTR) &cadena, 128);
hb_retc (cadena);
}
HB_FUNC (INSTALL_READ_KEYBOARD)
{
if (flag_hhk == FALSE)
{ hhk = SetWindowsHookEx (WH_KEYBOARD_LL, (HOOKPROC)KeyboardProc, hInst, 0 );
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