WH_KEYBOARD 對於全域性的效果不好用, 換用 WH_KEYBOARD_LL 鉤子吧。示例程式碼://全域性鍵盤鉤子訊息處理函式function KeyHookProc(nCode:Integer; wP:WPARAM; lP:LPARAM):LRESULT; stdcall;var pEvt: TEventMsg; vKey: Cardinal;begin if (nCode = HC_ACTION) then begin vKey := 0; case wP of WM_SYSKEYDOWN, WM_KEYDOWN: begin pEvt := PEventMsg(LP)^; vKey := LOBYTE(pEvt.message); case vKey of ...... end; end; end; WM_SYSKEYUP, WM_KEYUP:; end; end; result := CallNextHookEx(hKeyHook, nCode, wP, lP);end;安裝鉤子:hKeyHook := SetWindowsHookEx(WH_KEYBOARD_LL, @KeyHookProc, hInstance, 0);
WH_KEYBOARD 對於全域性的效果不好用, 換用 WH_KEYBOARD_LL 鉤子吧。示例程式碼://全域性鍵盤鉤子訊息處理函式function KeyHookProc(nCode:Integer; wP:WPARAM; lP:LPARAM):LRESULT; stdcall;var pEvt: TEventMsg; vKey: Cardinal;begin if (nCode = HC_ACTION) then begin vKey := 0; case wP of WM_SYSKEYDOWN, WM_KEYDOWN: begin pEvt := PEventMsg(LP)^; vKey := LOBYTE(pEvt.message); case vKey of ...... end; end; end; WM_SYSKEYUP, WM_KEYUP:; end; end; result := CallNextHookEx(hKeyHook, nCode, wP, lP);end;安裝鉤子:hKeyHook := SetWindowsHookEx(WH_KEYBOARD_LL, @KeyHookProc, hInstance, 0);