Intercept keyboard WIN button

xiaoxiao2021-03-06  107

Method a: function LowLevelKeyboardProc (nCode: integer; WParam: WPARAM; LParam: LPARAM): LRESULT; stdcall; typeKBDLLHOOKSTRUCT = record vkCode: DWORD; scanCode: DWORD; flags: DWORD; time: DWord; dwExtraInfo: dword; end; var fFlag : BOOL; p: ^ KBDLLHOOKSTRUCT; begin result: = 0; fFlag: = false; p: = Pointer (LPARAM); if (ncode = HC_ACTION) then begin case wparam of WM_KEYDOWN, WM_SYSKEYDOWN, WM_KEYUP, WM_SYSKEYUP: fFlag: = ( P.vkcode = vk_lwin) or (p.vkcode = vk_rwin) or (p.vkcode = vk_apps); end; end; if fflag = true kil = 1; if ncode <> 0 Then Result: = CallNexThookex (0, NCODE, WPARAM, LPARAM; END;

Procedure tform1.button1click (sender: Tobject); const wh_keyboard_ll = 13; begin setWindowshookexwwwwww (WH_KEYBOARD_LL, LOWLVELKEYBOARDPROC, HINSTANCE, 0); END; Method 2: Unit unit1;

Interface

Uses Windows, Messages, Sysutils, Variants, Classes, Graphics, Controls, Forms, Dialogs, Stdctrls;

type TForm1 = class (TForm) Button1: TButton; Edit1: TEdit; procedure Button1Click (Sender: TObject); private {Private declarations} public procedure WndProc (var Message: TMessage); override; {Public declarations} end;

Var Form1: TFORM1;

IMPLEMentation

{$ R * .dfm} var wm_sock: integer; hhandle: hwnd;

function LowLevelKeyboardProc (nCode: integer; WParam: WPARAM; LParam: LPARAM): LRESULT; stdcall; typeKBDLLHOOKSTRUCT = record vkCode: DWORD; scanCode: DWORD; flags: DWORD; time: DWord; dwExtraInfo: dword; end; var fFlag: BOOL; p: ^ KBDLLHOOKSTRUCT; begin result: = 0; fFlag: = false; p: = Pointer (LPARAM); if (ncode = HC_ACTION) then begin case wparam of WM_KEYDOWN, WM_SYSKEYDOWN, WM_KEYUP, WM_SYSKEYUP: fFlag: = (p.vkCode = VK_LWIN) OR (p.vkcode = vk_rwin) or (p.vkcode = vk_apps); end; end; if fflag = true, wm_sock, 0,0); result: = 1; end; if ncode <> 0 then Result: = CallNextHookEX (0, ncode, wparam, lparam); end; procedure TForm1.Button1Click (Sender: TObject); const WH_KEYBOARD_LL = 13; begin wm_sock: = 0; wm_sock: = RegisterWindowMessage ( 'wm_sock') // ShowMessage (INTTOSTR (WM_SOCK); hhandle: = self.handle;

Setwindowshookexwwwwww (wh_keyboard_ll, limited ", hinstance, 0);

Procedure TForm1.WndProc (Var Message: TMESSAGE); Begin if message.msg = WM_SOCK THEN BEGIN SHOWMESSAGE ('user presses WIN "); end; inherited;

End.

转载请注明原文地址:https://www.9cbs.com/read-102930.html

New Post(0)