Last active
October 12, 2024 23:22
-
-
Save davidglezz/7305932 to your computer and use it in GitHub Desktop.
Example of how to simulate a mouse click
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <windows.h> | |
int main() | |
{ | |
//allocate a data | |
INPUT *data = new INPUT[3]; | |
// Move to position. data | |
data->type = INPUT_MOUSE; | |
data->mi.dx = 0; // Position x | |
data->mi.dy = 0; // Position y | |
data->mi.mouseData = 0; | |
data->mi.dwFlags = (MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_MOVE); | |
data->mi.time = 0; | |
data->mi.dwExtraInfo = 0; | |
// Mouse down data | |
(data+1)->type = INPUT_MOUSE; | |
(data+1)->mi.dx = 0; | |
(data+1)->mi.dy = 0; | |
(data+1)->mi.mouseData = 0; | |
(data+1)->mi.dwFlags = MOUSEEVENTF_LEFTDOWN; | |
(data+1)->mi.time = 0; | |
(data+1)->mi.dwExtraInfo = 0; | |
// Mouse up data | |
(data+2)->type = INPUT_MOUSE; | |
(data+2)->mi.dx = 0; | |
(data+2)->mi.dy = 0; | |
(data+2)->mi.mouseData = 0; | |
(data+2)->mi.dwFlags = MOUSEEVENTF_LEFTUP; | |
(data+2)->mi.time = 0; | |
(data+2)->mi.dwExtraInfo = 0; | |
SendInput(3, data, sizeof(INPUT)); | |
delete (data); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
About INPUT structure:
http://msdn.microsoft.com/en-us/library/windows/desktop/ms646270(v=vs.85).aspx
http://msdn.microsoft.com/en-us/library/windows/desktop/ms646273(v=vs.85).aspx