Solved

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

Posted on 2003-11-08
5
269 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
Comment Utility
- 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
Comment Utility
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
Comment Utility
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
Comment Utility
In my opinion is important to convert to ClientToScreen.
0
 
LVL 1

Author Comment

by:Ne000
Comment Utility
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
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…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

771 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now