• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 404
  • Last Modified:

Mouse movement tracking

How can i make a program that will track the mouse movement in a specific window and in the start menu in windows ?
0
igor84
Asked:
igor84
  • 7
  • 6
  • 3
  • +4
1 Solution
 
edeyCommented:
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
 
GwenaCommented:
listening :-)
0
 
gemartiCommented:

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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
igor84Author Commented:


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
 
SlavakCommented:
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
 
igor84Author Commented:
ok, how i implement the all var in the cose i didn't understood what i need to do with all the vars ...
0
 
ginsonicCommented:
listening
0
 
SlavakCommented:
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
 
igor84Author Commented:
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
 
SlavakCommented:
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
 
edeyCommented:
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
 
igor84Author Commented:
to Slavak  :

how i get the Handel of the start menu ??

can you submit the full PAS file plase ?
0
 
SlavakCommented:
Can you tell me, what exactly you want to do?
0
 
igor84Author Commented:
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
 
edeyCommented:
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
 
igor84Author Commented:
Why no one writes a full PAS file so i can understood it right ???

Please Help Me !!!!


Igor
0
 
igor84Author Commented:
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
 
SlavakCommented:
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
 
SlavakCommented:
You can contact me <edited by PashaMod>
0
 
Russell LibbySoftware Engineer, Advisory Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

  • 7
  • 6
  • 3
  • +4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now