Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2003-11-08
5
Medium Priority
?
277 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 280 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 140 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

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…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

670 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