Solved

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

Posted on 2003-11-08
5
273 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
[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
  • 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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

Suggested Solutions

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…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

735 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