TYPE
PKBDLLHOOKSTRUCT = ^KBDLLHOOKSTRUCT;
KBDLLHOOKSTRUCT = record
vkCode: DWORD;
ScanCode: DWORD;
Flags: DWORD;
Time: DWORD;
dwExtraInfo: DWORD;
end;
var
hkNTKeyboard: HHOOK;
const
WH_KEYBOARD_LL = 13;
function LowLevelKeyboardFunc(nCode: Integer; wParam: WPARAM; lParam: LPARAM): LRESULT; stdcall;
procedure TForm1.FormCreate(Sender: TObject);
begin
SetWindowsHookEx(WH_KEYBOARD_LL, LowLevelKeyboardFunc, HInstance, 0);
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
UnhookWindowsHookEx(hkNTKeyboard);
end;
function LowLevelKeyboardFunc(nCode: Integer; wParam: WPARAM; lParam: LPARAM): LRESULT; stdcall;
var
p: PKBDLLHOOKSTRUCT;
begin
if not (nCode=HC_ACTION) then
begin
Result:=CallNextHookEx(0, nCode, wParam, lParam);
Exit;
end;
case wParam of
WM_KEYDOWN,
WM_SYSKEYDOWN:
begin
p:=PKBDLLHOOKSTRUCT(lParam);
if p^.vkCode = VK_LCONTROL then
SHOWMESSAGE('LEFT CTRL');
end;
WM_KEYUP,
WM_SYSKEYUP:
begin
p:=PKBDLLHOOKSTRUCT(lParam);
if p^.vkCode = VK_LCONTROL then
SHOWMESSAGE('LEFT CTRL');
end;
end;
Result:=CallNextHookEx(0, nCode, wParam, lParam);
end;