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

Record Mouse Movement And KeyDown

Experts....................

my delphi app sits in the traybar and when run a setup.exe
(any setup.exe) i want to monitor mouse movement and keystrokes in INI file, like some macro program do. I will be able to play it again with same speed and all?

I raise the points for complete code and answer

Points = ?

Regards
Karen
0
karen021897
Asked:
karen021897
  • 3
  • 2
  • 2
  • +4
1 Solution
 
MadshiCommented:
You'll need to call SetWindowsHookEx(WH_JOURNALRECORD, ...). Quite difficult stuff. Sorry, I've no time to write you some sources.
However, I don't understand what this has to do with "ini" files???

Regards, Madshi.
0
 
MadshiCommented:
P.S: The hook callback function for SetWindowsHookEx must be in a little self-written DLL, if you want it to work system-wide (that's what I guess)...
0
 
nricoCommented:
You could use a very accurate timer (it's him with his timers again :-), to monitor the mouse-movement through Mouse.CursorPos.X and Y. As for the keys, you need to hook the Windows keyboard handler, for which I have an example here:

http://www.experts-exchange.com/jsp/qShow.jsp?ta=delphi&qid=10171257 

Also, you can find a very accurate timer here:

http://www.silicmdr.com/Freeware.htm

But I do not know how to find out when a file called setup.exe is run. Sorry.

Hope these links will help,
Rico
0
Take Control of Web Hosting For Your Clients

As a web developer or IT admin, successfully managing multiple client accounts can be challenging. In this webinar we will look at the tools provided by Media Temple and Plesk to make managing your clients’ hosting easier.

 
MadshiCommented:
Oops... I missed the part with the setup.exe. Which Delphi version do you have, karen?
0
 
AswCommented:
Hi Karen,

Try www.cyamon.com and download Recorder.

Asw
0
 
yingkitCommented:
Recorder in www.cyamon.com seems to be unable to save the keystrokes and mouse movements into files.
After the termination of the program, all recorded keys, movt will be lost...
Anyway, it works fine if save is not required.
0
 
nricoCommented:
But *HOW* does it work?
0
 
craig_capelCommented:
well i know yet another method of recording the mouse movement, and i can even capture the keyboard using port $60 and that works.... there is only one thing i can not do with the mouse though, and that is to determine what mouse button get pressed, i can click on the buttons where the mouse is, control the mouse and do almost anything..... heres the code for all to see....

unit mouse1;

interface

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

type
  TForm1 = class(TForm)
    Timer1: TTimer;
    Button1: TButton;
    Button2: TButton;
    SaveDialog1: TSaveDialog;
    Edit1: TEdit;
    Button3: TButton;
    Edit2: TEdit;
    procedure Timer1Timer(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure FormMouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
 
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
    fn: string;

implementation

{$R *.DFM}

procedure TForm1.Timer1Timer(Sender: TObject);
var
 p: trect;
  fm,lm: word;
  n: integer;
  result: byte;
  t: textfile;
  x,y,num,num1,num2: integer;
  ms: dword;
  wnd: hwnd;
  tt: tmsg;
  p2: tpoint;
begin
  system.assign(t,fn);
  system.append(t);
  num:=getmessagepos();
   num1:=hiword(num);
   num2:=loword(num);
      p2.y:=num1;
      p2.x:=num2;
   wnd:=windowfrompoint(p2);
   asm
    in al,$60;
    mov result,al;
   end;
      if result=$3d then enablewindow(wnd,false);
       if result=$3e then enablewindow(wnd,true);
   edit1.text:=inttostr(wnd);

   writeln(t,num1);
   writeln(t,num2);
{   edit1.text:=inttostr(num1);
   edit2.text:=inttostr(num2);}
   system.close(t);
   x:=num2;
   y:=num1;
         {tt.hwnd:=form1.Handle;
         tt.message:=qs_mousebutton;}
          getmessage(nil,wnd,fm,lm);
{   ms:=getqueuestatus(QS_MOUSEBUTTON);}
   edit2.text:=inttostr(fm);

end;

procedure TForm1.Button1Click(Sender: TObject);
var
 tmp: string;
 t: textfile;
 slw,x,y,n: integer;
begin
 timer1.enabled:=false;
system.assign(t,fn);
  system.reset(t);
  repeat
        readln(t,tmp);
    readln(t,tmp);
    y:=strtoint(tmp);
    x:=strtoint(tmp);
     for slw:=1 to 10000 do
       application.processmessages;
    setcursorpos(x,y);
  until eof(t);
  system.close(t);
end;

procedure TForm1.Button2Click(Sender: TObject);
var
 t: textfile;
begin
savedialog1.execute;
fn:=savedialog1.filename;
  system.assign(t,fn);
  system.rewrite(t);
  timer1.enabled:=true;
    system.close(t);
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
if timer1.enabled=false then
close;
end;

procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
edit2.text:=' test';
end;

end.


i am hopeing some here knows the reverse command of....
sendmessage, and if i found out that, then you would not need a hook :)

Craig C.
0
 
craig_capelCommented:
oops, i forgot to see if the program works.....

procedure TForm1.Button1Click(Sender: TObject);
var
 tmp: string;
 t: textfile;
 slw,x,y,n: integer;
begin
 timer1.enabled:=false;
system.assign(t,fn);
  system.reset(t);
  repeat
        readln(t,tmp);
    y:=strtoint(tmp);
        readln(t,tmp);
    x:=strtoint(tmp);
     for slw:=1 to 10000 do
       application.processmessages;
    setcursorpos(x,y);
  until eof(t);
  system.close(t);
end;

this needs changing, and the first error message is getmessage, thats what i need help on myself :) but if you know how to make it work, half of this problem is solved... and the second error is that i read tmp twice in, just overwrite it with this code.... and then i promise it will work..

Craig C.
0
 
intheCommented:
theres an article with full source on this at borland:

http://community.borland.com/article/1,1410,10323,00.html
0
 
ahalyaCommented:
i have code for journalhook & playback, (based on borland's article), but with the following features

(1).   Save/Restore
(2).   Playback at different speeds
(3).   Hotkey activation for both recording andf playback.

i made this program to use as a "Macro" in Grapher & it ain't perfect, but it works well.

i can email you a copy, if you like.
(src is in D2: it shdn't be a concern)
0

Featured Post

[Webinar] Kill tickets & tabs using PowerShell

Are you tired of cycling through the same browser tabs everyday to close the same repetitive tickets? In this webinar JumpCloud will show how you can leverage RESTful APIs to build your own PowerShell modules to kill tickets & tabs using the PowerShell command Invoke-RestMethod.

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