unit RfidTest;
interface
implementation
uses
Winapi.Windows,
Winapi.Messages;
var
GlobalKeyboardHook: HHOOK;
RfidCode: string;
function KeyboardHook(nCode: Integer; wParam: WPARAM; lParam: LPARAM): LRESULT; stdcall;
type
PKeyboardLowLevelHookStruct = ^TKeyboardLowLevelHookStruct;
TKeyboardLowLevelHookStruct = record
KeyCode: Cardinal;
ScanCode: Cardinal;
Flags: Cardinal;
Time: Cardinal;
ExtraInfo: Cardinal;
end;
var
DllHook: PKeyboardLowLevelHookStruct;
begin
if nCode = HC_ACTION then
begin
DllHook := PKeyboardLowLevelHookStruct(lParam);
if (wParam = WM_KEYUP) or (wParam = WM_SYSKEYUP) then
begin
if (DllHook^.KeyCode >= Ord('0')) and (DllHook^.KeyCode <= Ord('9')) then
RfidCode := RfidCode + Char(DllHook^.KeyCode)
else if DllHook^.KeyCode = VK_RETURN then
begin
OutputDebugString(PWideChar('RFID-Code: ' + RfidCode));
RfidCode := '';
end;
end;
end;
Result := CallNextHookEx(GlobalKeyboardHook, nCode, wParam, lParam);
end;
procedure InitGlobalKeyboardHook();
begin
GlobalKeyboardHook := SetWindowsHookEx(WH_KEYBOARD_LL, @KeyboardHook, 0, 0);
if GlobalKeyboardHook = 0
then RaiseLastOSError;
end;
procedure KillGlobalKeyboardHook();
begin
if (GlobalKeyboardHook <> 0) then
UnhookWindowsHookEx(GlobalKeyboardHook);
end;
initialization
InitGlobalKeyboardHook();
finalization
KillGlobalKeyboardHook();
end.