Solved

Mouse movement tracking

Posted on 2001-07-24
21
387 Views
Last Modified: 2010-04-06
How can i make a program that will track the mouse movement in a specific window and in the start menu in windows ?
0
Comment
Question by:igor84
  • 7
  • 6
  • 3
  • +4
21 Comments
 
LVL 6

Expert Comment

by:edey
ID: 6314488
something like:

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  ExtCtrls;

type
  TForm1 = class(TForm)
    Timer1: TTimer;
    procedure Timer1Timer(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Timer1Timer(Sender: TObject);
begin
     caption := intToStr(mouse.cursorPos.x)+', '+intToStr(mouse.cursorPos.y);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
     timer1.Interval := 10;
end;

end.

GL
Mike
0
 
LVL 5

Expert Comment

by:Gwena
ID: 6314731
listening :-)
0
 
LVL 21

Expert Comment

by:gemarti
ID: 6315258

Converts the screen coordinates of a specified point on the screen to client coordinates.


procedure TForm1.Timer1Timer(Sender: TObject);
var
  lpPoint : TPoint;
begin
  lpPoint := ScreenToClient(Mouse.CursorPos);
  Label1.Caption := IntToStr(lpPoint.X);
  Label2.Caption := IntToStr(lpPoint.Y);
end;

or

?????????????????????????????
Translates a given point from client area coordinates to global screen coordinates:

procedure TForm1.Timer1Timer(Sender: TObject);
var
  lpPoint : TPoint;
begin
  lpPoint := ClientToScreen(Mouse.CursorPos);
  Label1.Caption := IntToStr(lpPoint.X);
  Label2.Caption := IntToStr(lpPoint.Y);
end;
0
 

Author Comment

by:igor84
ID: 6316036


are you kidding with you with me ????

the goal is to make a hook to the mousr in a sepcific window and not to track my window !!!

0
 
LVL 3

Expert Comment

by:Slavak
ID: 6316574
One way to do it, just change default window procedure of target window:

procedure TrackMouse(H : HWND);

Const
 LastProc : Pointer = nil;

 function MyProc(wnd : HWND; msg : Cardinal; wParam, lParam : Integer) : Integer; stdcall;
 Var
  X, Y  : Integer;
 Begin
  If Msg = WM_MOUSEMOVE Then begin
   X := lParam and $FFFF;
   Y := lParam shr 16;
   // your code here
 End;

 Result := CallWindowProc(LastProc, wnd, msg, wParam, lParam);
End;

Begin
 Integer(LastProc) := GetWindowLong(H, GWL_WNDPROC);
 SetWindowLong(H, GWL_WNDPROC, Integer(@MyProc));
End;
 
Regards.
0
 

Author Comment

by:igor84
ID: 6316581
ok, how i implement the all var in the cose i didn't understood what i need to do with all the vars ...
0
 
LVL 9

Expert Comment

by:ginsonic
ID: 6316599
listening
0
 
LVL 3

Expert Comment

by:Slavak
ID: 6316729
Tell me what u want.

I showed you how you can "track the mouse movement" on another window. In my code, X and Y variables in MyProc function gets mouse coordinates (relative to given window).
Tou can use them at this place (after comment "your code here").
 For example, add the line at this place:
Application.MainForm.Caption := Format('%d %d', [X, Y]);

Regards.




0
 

Author Comment

by:igor84
ID: 6316920
ok but where i need to inform your program what other program i want to track ?

and another thing is how i make it work on the start menu ?
0
 
LVL 3

Expert Comment

by:Slavak
ID: 6317059
To track the window, just call TrackMouse function.
The function has one parameter: handle of tracking window.
To find the handle you can use all API functions that returns window handle:FindWindow, WindowFromPoint etc..

Now, if you can tell me what you want to do with start menu, may be I can help you.
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 6

Expert Comment

by:edey
ID: 6317247
Yes, a little more explanation would seem to be in order.  I submitted a solution that fits the stated question quite well.  if you have other requirements, or simply asked your question rather poorly, now would be the time to clarify.

GL
Mike
0
 

Author Comment

by:igor84
ID: 6317625
to Slavak  :

how i get the Handel of the start menu ??

can you submit the full PAS file plase ?
0
 
LVL 3

Expert Comment

by:Slavak
ID: 6317701
Can you tell me, what exactly you want to do?
0
 

Author Comment

by:igor84
ID: 6317849
i want to see the way (the virtual line that the mouse create ) of the mouse in a specific program like word or ICQ or the start menu. i want to see the path of the mouse on a specific program ( Start Menu).

the demo need to show a contnius line that represents the mouse movement in the start menu ...

p.s what is your ICQ number if you have problems to understand my explention i will explan to you better in icq ...

Igor
0
 
LVL 6

Accepted Solution

by:
edey earned 73 total points
ID: 6318017
You should be able to get the handle with this:

start_handle := GetSystemMenu(FindWindow('Shell_TrayWnd', Nil), FALSE);

you can get a windows rect with the getWindowRect api. So in a timer, thread or hook (I'd sugest a thread) you can check the value of mouse.cursorPos against the rects (from getWindowRect) that you want to track.  From there you only have to decide how you want to keep the data points, anything from a TList to a temp canvas with Begin/End Path would work - depending on what you need to do with the data.

GL
Mike
0
 

Author Comment

by:igor84
ID: 6323932
Why no one writes a full PAS file so i can understood it right ???

Please Help Me !!!!


Igor
0
 

Author Comment

by:igor84
ID: 6323961
to Slavak :

Plase can you make me a full unit file i know how to declare all the functions ...

when you will do it and it will work you will get the points ...

i need it fast ...

Igor
0
 
LVL 3

Expert Comment

by:Slavak
ID: 6330839
What "unit file" you need? TrackMouse procedure, that I post, can track mouse on every user window (you should give a window handle as parameter). But you cannot track start system menu in this way (if I understand what you want :) ).

 
0
 
LVL 3

Expert Comment

by:Slavak
ID: 6330842
You can contact me <edited by PashaMod>
0
 
LVL 26

Expert Comment

by:Russell Libby
ID: 8732647
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

Accept edey's comment as answer

Please leave any comments here within the next seven days.
 
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
 
Thank you,
Russell

EE Cleanup Volunteer
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now