Try this :
****************************************************************************
* READ THE KEYBOARD
****************************************************************************
***************************************************************************************************
* DESCRIPTION
*
* Read keyboard input entries and returns information about the key pressed.
* These functions intercept keyboard messages from the system will send the application
* (WM_KEYUP and WM_KEYDOWN) and stores information about the virtual key generated.
*
***************************************************************************************************
* SYNTAX:
*
* INSTALL_READ_KEYBOARD () // Install the "driver" that reads the keyboard (returns. T. if successful)
* UNINSTALL_READ_KEYBOARD () // Uninstall the "driver" that reads the keyboard (returns. T. if successful)
*
* GET_LAST_VK() // Returns the virtual value (VK Code) of the key pressed
* GET_LAST_VK_NAME() // Returns the name of the virtual key press
*
* GET_STATE_VK_SHIFT () // Returns. T. if SHIFT key is pressed
* GET_STATE_VK_CONTROL () // Returns. T. if CONTROL key is pressed
* GET_STATE_VK_ALT () // Returns. T. if ALT key is pressed
*
* PAUSE_READ_VK (.T.) // Pause reading keyboard in order to process the key pressed
* PAUSE_READ_VK (.F.) // Restore keyboard reading after the pause
*
- Code: Select all Expand view
*##################################################################################################
* C code
*##################################################################################################
#pragma begindump
#include <windows.h>
#include "hbapi.h"
HB_BOOL flag_hhk = FALSE;
HB_BOOL PAUSE_hhk = FALSE;
HHOOK hhk = NULL;
HB_LONG VK_PRESIONADO = 0;
HB_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
- Code: Select all Expand view
add to dialog :
oDlg:bKeyDown := { |nKey,nFlag| Pressed(nKey) }
static function Press(nKey)
local cPressed := hb_ntos (GET_LAST_VK())
if GET_STATE_VK_SHIFT() == .T.
if hb_ntos (GET_LAST_VK()) == "118" // F7
endif
if hb_ntos (GET_LAST_VK()) == "119" // F8
endif
endif
if GET_STATE_VK_CONTROL() == .T.
endif
if nKey == 113 // f2
endif
if nKey == 45 // insert
endif
if nKey == 46 // delete
endif
return nil
Regards
Fafi