Solved

Mouse movement tracking

Posted on 2001-07-24
21
393 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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
 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…

734 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