Solved

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

Posted on 2003-11-08
5
275 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

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

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

Suggested Solutions

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
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…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

739 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