| | |
Simulate Mouse Move
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Aug 2004
Posts: 2
Reputation:
Solved Threads: 0
C++ Syntax (Toggle Plain Text)
#include "windows.h" int main(int argc, char* argv[]){ INPUT *buffer = new INPUT[3]; //allocate a buffer int X = 30; int Y = 50; SetCursorPos(X,Y); mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, X, Y, 0, 0 ); return 0; }
that works just fine
•
•
Join Date: Mar 2007
Posts: 1
Reputation:
Solved Threads: 0
I have used windows.h to move my cursor to a specific pixel on the screen. I do not know what type of style you are programming in because I only got errors with the cod you gave me but I do know that the code below works in a “Win32 Console application”. I have come across many automated mouse & keyboard artificial event simulators in c++, but all I came across that I could maintain is a few keyboard buttons and to move the mouse. Even though my main voyage was to purely get the mouse to click as fast is can for one of the games I have, I hope will help on your attempt to (as for why you want it to click at 100,100 is very strange to me).
As:
#include <iostream>
//#include<iostream.h>
//my compiler looks for iostream without “.h”, you may need to add
//it in as you copy this
#include <windows.h>
#include <conio.h>
//for getch() to pause at the end
usingnamespace std;
void main()
{
//get the position of cursor first
cout<<"pos before change"<<endl;
POINT pos;
GetCursorPos(&pos);
int x=pos.x;
int y=pos.y;
Sleep(10);
cout<<"x:"<<x<<", "<<"y:"<<y<<endl;
cout<<"pos set to 100,100"<<endl;
//MOVEMENT HERE \/\/\/
SetCursorPos(100,100);
//get cursor pos again
GetCursorPos(&pos);
x=pos.x;
y=pos.y;
Sleep(10);
cout<<"x:"<<x<<", "<<"y:"<<y<<endl;
cout<<"pos set set to x+1,y-1 (if mouse not moving, it should be 101,99)"<<endl;
//set again();
GetCursorPos(&pos);
x=pos.x;
y=pos.y;
SetCursorPos(x+1,y-1);
//read for the last time
GetCursorPos(&pos);
x=pos.x;
y=pos.y;
Sleep(10);
cout<<"x:"<<x<<", "<<"y:"<<y<<endl;
cout<<"press any key to exit";
getch();
}
As:
#include <iostream>
//#include<iostream.h>
//my compiler looks for iostream without “.h”, you may need to add
//it in as you copy this
#include <windows.h>
#include <conio.h>
//for getch() to pause at the end
usingnamespace std;
void main()
{
//get the position of cursor first
cout<<"pos before change"<<endl;
POINT pos;
GetCursorPos(&pos);
int x=pos.x;
int y=pos.y;
Sleep(10);
cout<<"x:"<<x<<", "<<"y:"<<y<<endl;
cout<<"pos set to 100,100"<<endl;
//MOVEMENT HERE \/\/\/
SetCursorPos(100,100);
//get cursor pos again
GetCursorPos(&pos);
x=pos.x;
y=pos.y;
Sleep(10);
cout<<"x:"<<x<<", "<<"y:"<<y<<endl;
cout<<"pos set set to x+1,y-1 (if mouse not moving, it should be 101,99)"<<endl;
//set again();
GetCursorPos(&pos);
x=pos.x;
y=pos.y;
SetCursorPos(x+1,y-1);
//read for the last time
GetCursorPos(&pos);
x=pos.x;
y=pos.y;
Sleep(10);
cout<<"x:"<<x<<", "<<"y:"<<y<<endl;
cout<<"press any key to exit";
getch();
}
![]() |
Similar Threads
- Change backColor of Button When Mouse Move over it (ASP.NET)
- Simulate Mouse Click (Visual Basic 4 / 5 / 6)
- how to simulate mouse movement and click (C)
Other Threads in the C++ Forum
- Previous Thread: Pointer to array
- Next Thread: GUI colouring
| Thread Tools | Search this Thread |
api application array arrays based beginner binary bmp c++ c/c++ calculator char char* class classes code compile compiler console conversion count delete deploy directshow dll download dynamic dynamiccharacterarray email encryption error file format forms fstream function functions game givemetehcodez google graph gui homeworkhelp iamthwee ifstream input int java lib library linkedlist linker list loop looping loops map math matrix memory microsoft newbie news number numbertoword output pointer problem program programming project python random read recursion recursive reference rpg simple sorting string strings temperature template test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets





