Simulate input/Mouse: Difference between revisions

Added C implementation for Windows.
No edit summary
(Added C implementation for Windows.)
Line 10:
Click 400, 400 right ; relative to top left corner of the screen.</lang>
 
=={{header|C}}==
===Windows===
Animates the movement of the mouse pointer from the screen center to the bottom left corner where the Windows button is usually present on most Windows desktops. Once there, a left click is simulated. The exact speed, motion and behaviour of the pointer will vary from desktop to desktop. Compatible with MinGW or GCC for Windows.
<lang C>
/*Abhishek Ghosh, 10th October 2017*/
 
#define WINVER 0x500
#include<windows.h>
 
int main()
{
int maxX = GetSystemMetrics(SM_CXSCREEN), maxY = GetSystemMetrics(SM_CYSCREEN);
int x = maxX/2, y = maxY/2;
double factorX = 65536.0 / maxX,factorY = 65536.0 / maxY;
INPUT ip;
ZeroMemory(&ip,sizeof(ip));
ip.type = INPUT_MOUSE;
while(x > 5 || y < maxY-5){
 
ip.mi.mouseData = 0;
ip.mi.dx = x * factorX;
ip.mi.dy = y * factorY;
ip.mi.dwFlags = MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_MOVE;
SendInput(1,&ip,sizeof(ip));
sleep(1);
if(x>3)
x-=1;
if(y<maxY-3)
y+=1;
}
ip.mi.dwFlags = MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP;
SendInput(1,&ip,sizeof(ip));
return 0;
}
</lang>
=={{header|Common Lisp}}==
{{libheader|xdotool}}
503

edits