Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- unit Unit1;
- interface
- uses
- Windows, Messages, Classes, Controls, Forms, StdCtrls;
- type
- TForm1 = class(TForm)
- ListBox1: TListBox;
- procedure FormCreate(Sender: TObject);
- procedure FormDestroy(Sender: TObject);
- end;
- var
- Form1: TForm1;
- implementation
- {$R *.dfm}
- const
- WH_KEYBOARD_LL = 13;
- type
- tagKBDLLHOOKSTRUCT = packed record
- vkCode: DWORD;
- scanCode: DWORD;
- flags: DWORD;
- time: DWORD;
- dwExtraInfo: Integer;
- end;
- KBDLLHOOKSTRUCT = tagKBDLLHOOKSTRUCT;
- PKBDLLHOOKSTRUCT = ^KBDLLHOOKSTRUCT;
- var
- hkHook: HHook;
- function LowLevelKeyboardProc(Code, wParam, lParam: Integer): LRESULT; stdcall;
- var
- KeyState: TKeyboardState;
- NewChar: array[0..1] of Char;
- Hook: PKBDLLHOOKSTRUCT;
- begin
- try
- Hook := Pointer(lParam);
- case Code of
- HC_ACTION:
- if wParam = WM_KEYDOWN then
- begin
- FillChar(NewChar, 2, #0);
- GetKeyboardState(KeyState);
- ToAscii(Hook^.vkCode, Hook^.scanCode, KeyState, NewChar, 0);
- case NewChar[0] of
- 'a'..'z', 'A'..'Z':
- Form1.ListBox1.Items.Add('Латинская буква: ' + NewChar[0]);
- 'а'..'я', 'А'..'Я', 'ё', 'Ё':
- Form1.ListBox1.Items.Add('Русская буква: ' + NewChar[0]);
- '0'..'9':
- Form1.ListBox1.Items.Add('Цифра: ' + NewChar[0]);
- else
- Form1.ListBox1.Items.Add('Другое: ' + NewChar[0]);
- end;
- end;
- end;
- finally
- Result := CallNextHookEx(hkHook, Code, wParam, lParam);
- end;
- end;
- procedure TForm1.FormCreate(Sender: TObject);
- begin
- hkHook := SetWindowsHookEx(WH_KEYBOARD_LL, @LowLevelKeyboardProc, hInstance, 0);
- end;
- procedure TForm1.FormDestroy(Sender: TObject);
- begin
- UnHookWindowsHookEx(hkHook);
- end;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement