Hallo zusammen,
habe ein Problem. ich habe eine kleinen hook geschrieben, der wichtige systemkombinationen blockt.
dieser klappt auch soweit ganz gut. allerdings lässt er machmal die explorer.exe abstürzen... ich habe keine ahnung warum und kenne mich leider auch nicht so gut damit aus...
könnte es daran liegen, dass ich manche kombinationen doppelt abfange? einmal mit WH_GetMessage plus WM_HOTKEY und noch einmal mit einen LowLevel Hook?
Hier der code:
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119:
| library Hook;
uses Windows, Messages, SysUtils, Dialogs;
{$R *.res}
type KBDLLHOOKSTRUCT = record vkCode: DWORD; scanCode: DWORD; flags: DWORD; time: DWORD; dwExtraInfo: DWORD; end; PKBDLLHOOKSTRUCT = ^KBDLLHOOKSTRUCT;
const WH_KEYBOARD_LL = 13; LLKHF_ALTDOWN = $00000020;
var SysKeyHook : Cardinal = 0; HotKeyHook : Cardinal = 0;
function HookSysKey(nCode: Integer; wParam: Cardinal; lParam: PMSG): LRESULT; stdcall; var pkh : PKBDLLHOOKSTRUCT; bCtrlKeyDown : BOOL; begin pkh := PKBDLLHOOKSTRUCT(lParam);
if nCode = HC_ACTION then begin bCtrlKeyDown := GetAsyncKeyState(VK_CONTROL) shr ((sizeof(SHORT) * 8) - 1) <> 0; if ((pkh^.vkCode = VK_ESCAPE) and bCtrlKeyDown) or ((pkh^.vkCode = VK_TAB) and (pkh^.flags and LLKHF_ALTDOWN = LLKHF_ALTDOWN)) or ((pkh^.vkCode = VK_ESCAPE) and (pkh^.flags and LLKHF_ALTDOWN = LLKHF_ALTDOWN)) or ((pkh^.vkCode = VK_LWIN) or (pkh^.vkCode = VK_RWIN)) then begin result := 1; exit; end; end; result := CallNextHookEx(SysKeyHook, nCode, wParam, Cardinal(lParam)); end;
function HookHotKey(nCode: Integer; wParam: Cardinal; lParam: PMSG): LRESULT; stdcall; begin if (nCode >= HC_ACTION) and (lParam^.message = WM_HOTKEY) then begin if (lParam^.wParam = 500) or (lParam^.wParam = 510) or (lParam^.wParam = 49203) then begin Result := 1; Exit; end else ShowMessage(IntToStr(lParam^.wParam)); end; result := CallNextHookEx(HotKeyHook, nCode, wParam, Cardinal(lParam)); end;
function InstallHook: Boolean; var SysKey, HotKey : Boolean; begin SysKey := SysKeyHook = 0; if SysKey then begin SysKeyHook := SetWindowsHookEx(WH_KEYBOARD_LL, @HookSysKey, hInstance, 0); SysKey := SysKeyHook <> 0; end;
HotKey := HotKeyHook = 0; if HotKey then begin HotKeyHook := SetWindowsHookEx(WH_GETMESSAGE, @HookHotKey, hInstance, 0); SysKey := SysKeyHook <> 0; end;
Result := SysKey and Hotkey; end;
function UnInstallHook: Boolean; var SysKey, HotKey : Boolean; begin SysKey := UnhookWindowsHookEx(SysKeyHook); SysKeyHook := 0;
HotKey := UnhookWindowsHookEx(HotKeyHook); HotKeyHook := 0;
Result := SysKey and Hotkey; end;
exports InstallHook, UnInstallHook;
begin end. |
Vielleicht weiß ja jemand rat
gruß