Hi tino,
wirklich tolles
tutorial !
ich hab irgendwie ein prob, der keyboardhook sollte doch global sein, funktioniert bei mir aber nur wenn des Form den Focus hat, hab mich eigentlich eng an deine vorlage gehalten um mal die funktionalität zu testen.
Dann hätte ich noch ne andere frage, ich würde gerne eine offene install prozedur für meine dll schreiben, sodas ich ihr per referenz die entsprechende hookproc (die natürlich dann individuell ausserhalb geschrieben wird) zuweise, ist dieser hook dann immer noch global wirksam ? oder muss ich etwa immer meine dll erweitern.
hier is 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:
| library My_Hook;
uses Windows, Messages;
{$R *.res}
Const WM_HOOKMESSAGEID = WM_USER + 5000;
Type THookProc = function (nCode: Integer; wParam: WPARAM; lParam: LPARAM): LRESULT; stdcall;
var HookHandle : Cardinal = 0; WindowHandle : Cardinal = 0;
function KeyboardHookProc(nCode: Integer; wParam: WPARAM; lParam: LPARAM): LRESULT; stdcall; begin Result := CallNextHookEx(HookHandle, nCode, wParam, lParam); case nCode < 0 of TRUE : exit; FALSE : begin Postmessage(WindowHandle,WM_HOOKMESSAGEID,Integer(wParam),Integer(LPARAM)); end; end; end;
function InstallKeyboardHook(Hwnd: Cardinal): Boolean; stdcall; begin Result := False; if HookHandle = 0 then begin HookHandle := SetWindowsHookEx(WH_KEYBOARD, @KeyboardHookProc, HInstance, 0); WindowHandle := Hwnd; Result := TRUE; end; end;
function InstallHook( IDHook : integer; HookProc : THookProc ): Cardinal; stdcall; begin Result := 0; if (HookHandle = 0)AND(@HookProc<>NIL) then begin HookHandle := SetWindowsHookEx(IDHook, @HookProc, HInstance, 0); Result := HookHandle; end; end;
function UninstallHook: Boolean; stdcall; begin Result := UnhookWindowsHookEx(HookHandle); HookHandle := 0; end;
exports InstallKeyboardHook, InstallHook, UninstallHook;
begin
end. |
Moderiert von
Tino: Topic getrennt; Link eingefügt; Code- durch Delphi-Tags ersetzt.