Free to do nothing, under the Win2K with BCB5 do a keyboard hook applet, monitor the global key situation. The hook placement and callback functions are placed in a separate DLL, and the DLL's original code is as follows:
//----------------------------------------------------------------------------------------------------
extern "C" __declspec (dllexport) void __stdcall sethook (hwnd,bool);
LRESULT CALLBACK hookproc (int ncode,wparam wparam,lparam LPARAM)
//----------------------------------------------------------------------------------------------------
Static HINSTANCE hinstance; Apply instance Handle
Static HWND Hwndmain; MainForm Handle
Static Hhook Hkeyhook; Hook handle
static const mymessage=2000; Custom message number
static const secondpar=1; Custom message 2nd parameter
//----------------------------------------------------------------------------------------------------
int WINAPI DllEntryPoint (hinstance hinst, unsigned long reason, void* lpreserved)
{hinstance=hinst; return 1;}
//----------------------------------------------------------------------------------------------------
void __stdcall Sethook (HWND hmainwin,bool ncode)
{
if (ncode)//placement Hook
{
Hwndmain=hmainwin;
Hkeyhook=setwindowshookex (Wh_journalrecord, (HookProc) hookproc,hinstance,0);
}
else//Remove hook
UnhookWindowsHookEx (Hkeyhook);
}
//----------------------------------------------------------------------------------------------------
LRESULT CALLBACK hookproc (int ncode,wparam wparam,lparam LPARAM)
{
Eventmsg *keymsg= (eventmsg *) LParam;
if ((ncode==hc_action) && (Keymsg->message==wm_keyup)
PostMessage (Hwndmain,mymessage, (char) (KEYMSG->PARAML), secondpar);
Send a message to the calling form Mymessage and virtual key Code (char) (KEYMSG->PARAML)
return ((int) CallNextHookEx (hkeyhook,ncode,wparam,lparam));
}
//----------------------------------------------------------------------------------------------------
The application code is as follows: (Tuning DLL)
//----------------------------------------------------------------------------------------------------
Static HINSTANCE hDLL; DLL handle
typedef void __stdcall (*dllfun) (Hwnd,bool);
Dllfun Dllsethook;
static const mymessage=2000;
static const secondpar=1;
//----------------------------------------------------------------------------------------------------
__fastcall Tform1::tform1 (tcomponent* owner): Tform (owner)
{}
//----------------------------------------------------------------------------------------------------
void __fastcall tform1::formcreate (tobject *sender)
{
Hdll=loadlibrary ((LPCTSTR) "Project1.dll"); DLL file name: Project1.dll
if (hdll==null)
{ShowMessage ("DLL: Cannot load!) Program exits. "); Exit (1); }
Dllsethook = (dllfun) GetProcAddress (hDLL, "Sethook");
if (dllsethook==null)
{ShowMessage ("DLL: Function not found!) Program exits. "); FreeLibrary (hDLL); Exit (1); }
Dllsethook (this->handle,true);
}
//----------------------------------------------------------------------------------------------------
void __fastcall Tform1::formclose (tobject *sender, tcloseaction &action)
{
Dllsethook (Null,false); Remove Hook
FreeLibrary (hDLL); Remove DLL
}
//----------------------------------------------------------------------------------------------------
void __fastcall tform1::applicationevents1message (tagmsg &msg,bool &handled)
{//BCB5.0 ApplicationEvents components
if ((msg.message==mymessage) && (Msg.lparam==secondpar)
ShowMessage ("Receive the hook button message!") \ n \ nthe "key virtual code": "+inttostr (Msg.wparam));
}
//----------------------------------------------------------------------------------------------------
Hook with Wh_journalrecord type is simple to implement.