Hook-based solution

xiaoxiao2021-03-06  20

What is hook, and the hook is actually inserted into a function in the message chain to monitor the message. Of course this hook acts as a role of the message. For monitoring is that system messages cannot be encapsulated with an EXE file because the EXE process is opaque for other processes. Then what should I do, of course, I think of a DLL file, map the DLL to other process space, and don't solve it. Below the hook of a keyboard - filtering WM_KEYDOWN, WM_KEYUP button messages. Main program UseHook; uses Windows; var mStruct: TMsg; procedureHookOn; external 'pggpjjhook.dll'; procedure HookOff; external 'pggpjjkook.dll'; begin HookOn; // hook While GetMessage (mStruct, 0, 0 0) DO; // message loop                                                             Keyboard status hookh: dWord; // hook handle fileh: dWord; // file handle fsize: dword = 1; // To write the length WSIZE: DWORD;     Recognition length fchar: array [0..1] of char;                                                                                             ((lParam shr 31) and 1) = 0) THEN / / Button Message Team Active Begin   GetKeyboardState (KBS); //                 SHR 16) and $ 000000FF), KBS, @fchar [0], 0) = 1 Then                                                                                                                                                     # E, WSIZE, NIL); // Write key ASCII value                                                                                                                        # ; begin HookH: = SetWindowsHookEx (WH_KEYBOARD, KeyHookPro, hInstance, 0); end;  // decoupling procedure hookOff; begin UnHookWindowsHookEx (HookH); end; exports HookOn, hookOff; begin end.

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

New Post(0)