ginsonic
asked on
Hook the mouse
I found some time ago a good tip how to hook the mouse at www.delphi300.com . Work perfect on Win9x, but when I tested under XP fail .
Same author upload a keyboards hook and this work perfect for both systems!?
SO, my question is:
How can I hook the mouse under Win9x and XP , too .
Same author upload a keyboards hook and this work perfect for both systems!?
SO, my question is:
How can I hook the mouse under Win9x and XP , too .
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Could you send it to me too. Thanks! delfreak@thedoghousemail.c om
ASKER
Inthe , sorry for delay .
The code is ~ what I need (and work under XP), except the x and y cursor coordonation.
How can I get these ?
Regards,
Nick
P.S. How get my website address ? :P
The code is ~ what I need (and work under XP), except the x and y cursor coordonation.
How can I get these ?
Regards,
Nick
P.S. How get my website address ? :P
er .. my name is neo :)
hehe when you read this you probably remember
(im sure you would've used this before as quite common though mayb not so anyway here it is )
to Get the Cursor Pos use GetCursorPos() by in HookDLL.Dpr change the callback to:
function MouseHookCallBack(Code: integer; Msg: word; MouseHook: longint): longint; export;
{$ENDIF}
var
p : tpoint;
begin
if Code >= 0 then begin
if Msg = WM_RBUTTONDOWN then
begin
getcursorpos(p);
MessageBeep(1);
Showmessage('x = ' +inttostr(p.x)+', y = '+inttostr(p.y));
end;
Result := CallNextHookEx(HookHandle, Code, Msg, MouseHook);
end else
Result := CallNextHookEx(HookHandle, Code, Msg, MouseHook);
end;
hope thats what your after,also have to add "sysutils" and "dialogs" to uses section
(for inttostr and showmessage functions)
Regards Barry
hehe when you read this you probably remember
(im sure you would've used this before as quite common though mayb not so anyway here it is )
to Get the Cursor Pos use GetCursorPos() by in HookDLL.Dpr change the callback to:
function MouseHookCallBack(Code: integer; Msg: word; MouseHook: longint): longint; export;
{$ENDIF}
var
p : tpoint;
begin
if Code >= 0 then begin
if Msg = WM_RBUTTONDOWN then
begin
getcursorpos(p);
MessageBeep(1);
Showmessage('x = ' +inttostr(p.x)+', y = '+inttostr(p.y));
end;
Result := CallNextHookEx(HookHandle,
end else
Result := CallNextHookEx(HookHandle,
end;
hope thats what your after,also have to add "sysutils" and "dialogs" to uses section
(for inttostr and showmessage functions)
Regards Barry
ASKER
Sorry Barry ...neo :)
I know GetCursorPos function . The tip founded by me on net get the coordonates from message . Don't use another function.
I upload the tip on my site for a short time:
www.ginsonic.ro\hook.txt.
I know GetCursorPos function . The tip founded by me on net get the coordonates from message . Don't use another function.
I upload the tip on my site for a short time:
www.ginsonic.ro\hook.txt.
ASKER
Sorry , try this link www.ginsonic.ro\hook.txt .
interesting way to get it via the message itself,didnt think of that one ;-)
ASKER
Can you help me to combine your tip with mine ( mine - not really mine - don't work for XP ) to get X,Y points?
I don't have work untill now with hooks and in same time I'm bussy to release my new version of TgnDBGrid .
HELP ME and I will accept your comment with A grade .
I don't have work untill now with hooks and in same time I'm bussy to release my new version of TgnDBGrid .
HELP ME and I will accept your comment with A grade .
two probs,
i dont have xp & i dont know which part is failing (thats why i had to send you example to test).
which parts do you need to combine?
cause i thought the example i sent was working under xp ?
do you want to merge the callbacks ,
very untested :
function MouseHookCallBack(Code: integer; Msg: word; MouseHook: longint): longint; export;
{$ENDIF}
var
DatosMouse : PMouseHookStruct;
Intentos : integer;
begin
if Code = HC_ACTION then begin
if Msg = WM_RBUTTONDOWN then
begin
FicheroM:=OpenFileMapping( FILE_MAP_R EAD,False, 'ElRecepto r');
if FicheroM<>0 then
begin
Compartido:=MapViewOfFile( FicheroM,F ILE_MAP_RE AD,0,0,0);
DatosMouse:=Pointer(lparam );
Compartido^.Ventana:=Datos Mouse^.hwn d;
Compartido^.x:=DatosMouse^ .pt.x;
Compartido^.y:=DatosMouse^ .pt.y;
PostMessage(Compartido^.Re ceptor,CM_ MANDA_DATO S,wParam,l Param);
UnmapViewOfFile(Compartido );
CloseHandle(FicheroM);
end; //FicheroM = 0
end; //Msg not right mouse button
Result := CallNextHookEx(HookHandle, Code, Msg, MouseHook);
end else //code not hc_action
Result := CallNextHookEx(HookHandle, Code, Msg, MouseHook);
end; //callback
i dont have xp & i dont know which part is failing (thats why i had to send you example to test).
which parts do you need to combine?
cause i thought the example i sent was working under xp ?
do you want to merge the callbacks ,
very untested :
function MouseHookCallBack(Code: integer; Msg: word; MouseHook: longint): longint; export;
{$ENDIF}
var
DatosMouse : PMouseHookStruct;
Intentos : integer;
begin
if Code = HC_ACTION then begin
if Msg = WM_RBUTTONDOWN then
begin
FicheroM:=OpenFileMapping(
if FicheroM<>0 then
begin
Compartido:=MapViewOfFile(
DatosMouse:=Pointer(lparam
Compartido^.Ventana:=Datos
Compartido^.x:=DatosMouse^
Compartido^.y:=DatosMouse^
PostMessage(Compartido^.Re
UnmapViewOfFile(Compartido
CloseHandle(FicheroM);
end; //FicheroM = 0
end; //Msg not right mouse button
Result := CallNextHookEx(HookHandle,
end else //code not hc_action
Result := CallNextHookEx(HookHandle,
end; //callback
ASKER
Sorry , sorry , sorry.
Was capture by a project.
I put your last comment in initial DLL . But I receive errors !?!
mousePos:=MapViewOfFile(FM ,FILE_MAP_ READ,0,0,0 );
DataMouse:=Pointer(lparam) ;
[Error] Hookdll.dpr(40): '(' expected but ')' found
MousePos^.Named:=DataMouse ^.hwnd;
MousePos^.x:=DataMouse^.pt .x;
MousePos^.y:=DataMouse^.pt .y;
PostMessage(MousePos^.Rece ptor,CM_MO USE,wParam ,lParam);
[Error] Hookdll.dpr(44): '(' expected but ',' found
UnmapViewOfFile(MousePos);
CloseHandle(FM);
Was capture by a project.
I put your last comment in initial DLL . But I receive errors !?!
mousePos:=MapViewOfFile(FM
DataMouse:=Pointer(lparam)
[Error] Hookdll.dpr(40): '(' expected but ')' found
MousePos^.Named:=DataMouse
MousePos^.x:=DataMouse^.pt
MousePos^.y:=DataMouse^.pt
PostMessage(MousePos^.Rece
[Error] Hookdll.dpr(44): '(' expected but ',' found
UnmapViewOfFile(MousePos);
CloseHandle(FM);
:see mousehook callback struct ,its different so
:=Pointer(lparam);
should be
:=Pointer(mousehook);
and
(Compartido^.Receptor,CM_M ANDA_DATOS ,wParam,lP aram);
should be
(Compartido^.Receptor,CM_M ANDA_DATOS ,msg,mouse hook);
the spanish names are confusing for me to read <g>
realise if it actually works you would also need to createfilemapping in your main project files to use the hook.
(see demo of the hook/txt you posted on your website ,i aslo have saved this demo from ages ago i just found it on my comp and the example it comes with shows how to use it so i guess you realise about file mapping issues.)
:=Pointer(lparam);
should be
:=Pointer(mousehook);
and
(Compartido^.Receptor,CM_M
should be
(Compartido^.Receptor,CM_M
the spanish names are confusing for me to read <g>
realise if it actually works you would also need to createfilemapping in your main project files to use the hook.
(see demo of the hook/txt you posted on your website ,i aslo have saved this demo from ages ago i just found it on my comp and the example it comes with shows how to use it so i guess you realise about file mapping issues.)
while im here:
this is a (quite long) text that we sometimes post here for learning about hoks /callbacks filemapping etc,maybe of interest to you:
http://groups.google.com/groups?q=The+following+example+demonstrates+creating+a+system+wide+windows&hl=en&selm=36CF41A4.3069%40gte.net&rnum=1
this is a (quite long) text that we sometimes post here for learning about hoks /callbacks filemapping etc,maybe of interest to you:
http://groups.google.com/groups?q=The+following+example+demonstrates+creating+a+system+wide+windows&hl=en&selm=36CF41A4.3069%40gte.net&rnum=1
ASKER
can't maked to work :(