Solved

Move the mouse to a position and click there, in a game

Posted on 2003-11-08
5
271 Views
Last Modified: 2010-04-05
Hi all... I want to make a small bot only for myself :)
I want to run the program in the background, and use it with short-cuts, while the game is running...
How can I:
- Move the mouse and then click
- Make short-cuts, that the programs respondig, if its not focused

Please help...
Greets Ne000
0
Comment
Question by:Ne000
  • 3
5 Comments
 
LVL 9

Accepted Solution

by:
ginsonic earned 70 total points
ID: 9709580
- Make short-cuts, that the programs respondig, if its not focused
Can be done very easy hooking the keyboard.

- Move the mouse and then click
...
var
  P: TPoint;
begin
 P.X := MyXCoord;
 P.Y := MyYCoord;
 P:=ClientToScreen( P );
 SetCursorPos( P.X, P.Y );
 mouse_event( MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0 );
 mouse_event( MOUSEEVENTF_LEFTUP, 0, 0, 0, 0 );
end;

if you wish to hide mouse movement (let the mouse where is it but do the clcik on wished position):

var
  P, O : TPoint;
begin
  P.X := MyXCoord;
  P.Y := MyYCoord;
  P:=ClientToScreen( P );
  GetCursorPos( O );
  SetCursorPos( P.X, P.Y );
  mouse_event( MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0 );
  mouse_event( MOUSEEVENTF_LEFTUP, 0, 0, 0, 0 );
  SetCursorPos( O.X, O.Y );
end;
0
 
LVL 17

Assisted Solution

by:geobul
geobul earned 35 total points
ID: 9714833
Hi,

The same as above posted by ginsonic but in absolute screen coordinates X and Y:

procedure MouseMoveAndClick(x, y: Integer);
var
 OldCoord: TPoint;
begin
 // save current position
 GetCursorPos(OldCoord);
 // move to new position
 SetCursorPos(x, y);
 // click
 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
 // restore position
 SetCursorPos(OldCoord.x, OldCoord.y);
end;

Regards, Geo
0
 
LVL 9

Expert Comment

by:ginsonic
ID: 9715505
geobul, can you tell me what is the difference between our codes ?

/// The same as above posted by ginsonic but in absolute screen coordinates X and Y:
0
 
LVL 9

Expert Comment

by:ginsonic
ID: 9715526
In my opinion is important to convert to ClientToScreen.
0
 
LVL 1

Author Comment

by:Ne000
ID: 9773854
Sorry, I forgot to give you points :P
Both solutions are good, but ginsonic was the first, so he gets more points... these are the rules :P

Greets Ne000
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

770 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