Mouse Hook without DLL implementation

xiaoxiao2021-03-06  38

This method can monitor the mouse movement outside of the FORM, no DLL implementation unit Unit1;

Interface

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

type TForm1 = class (TForm) Button1: TButton; procedure Button1Click (Sender: TObject); procedure FormClose (Sender: TObject; var Action: TCloseAction); private {Private declarations} Procedure Hook (En: Boolean = true); public {Public Declarations}

Var Form1: TForm1; HHOOK: longword; xy: tpoint;

IMPLEMentation

{$ R * .dfm} function hookproc (icode: integer; wparam: wparam; lparam: lparam): LRESULT; STDCALL; Begin

Result: = 0; If (peventmsg (lparam) ^ message = WM_LBUTTONDOWN.) Or (peventmsg (lparam) ^ message = WM_LBUTTONUP.) Or (peventmsg (lparam) ^ message = WM_LBUTTONDBLCLK.) Or (peventmsg (lparam) ^ message. = WM_MOUSEMOVE) Or (peventmsg (lparam) ^. message = WM_RBUTTONDOWN) Or (peventmsg (lparam) ^. message = WM_RBUTTONUP) Or (peventmsg (lparam) ^. message = WM_RBUTTONDBLCLK) Or (peventmsg (lparam) ^. message = WM_MBUTTONDOWN ) Or (peventmsg (lparam) ^ message = WM_MBUTTONUP) Or (peventmsg (lparam) ^ message = WM_MBUTTONDBLCLK) Then Begin GETCURSORPOS (XY); form1.Caption:.. = IntToStr (XY.x) '' IntToStr (XY End; Result: = CallneXthooKex (HHOOK, ICODE, WPARAM, LPARAM);

END;

Procedure TFORM1.BUTTON1CLICK (Sender: TOBJECT); Begin Hook;

END;

Procedure tform1.hook (en: boolean); begin if en dam: = setwindowshookex (Wh_JournalRecord, HookProc, Hinstance, 0) Else UnHookWindowsHookex (hHOOK);

END;

Procedure TFORM1.FORMCLOSE (Sender: Tobject; VAR Action: Tclosection); Begin Hook (false);

END;

End.

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

New Post(0)