Skip to content

Instantly share code, notes, and snippets.

@smvd
Created May 9, 2021 11:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save smvd/8ee0def076edbcae42cc94c8f0aa5d3e to your computer and use it in GitHub Desktop.
Save smvd/8ee0def076edbcae42cc94c8f0aa5d3e to your computer and use it in GitHub Desktop.
/*
[1] - https://docs.microsoft.com/en-us/windows/win32/winprog/using-the-windows-headers
[2] - https://www.tutorialspoint.com/c_standard_library/stdio_h.htm
[3] - https://www.tutorialspoint.com/cprogramming/c_functions.htm
[4] - https://docs.microsoft.com/en-us/windows/win32/api/winuser/ns-winuser-input
[5] - https://docs.microsoft.com/en-us/windows/win32/api/winuser/ns-winuser-mouseinput
[6] - https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-sendinput
[7] - https://www.tutorialspoint.com/cprogramming/index.htm
[8] - https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getasynckeystate
[9] - https://docs.microsoft.com/en-us/windows/win32/inputdev/virtual-key-codes
[10] - https://www.tutorialspoint.com/cprogramming/c_decision_making.htm
[11] - https://www.tutorialspoint.com/cprogramming/c_loops.htm
*/
#include <windows.h> // [1] Standard windows header
#include <stdio.h> // [2] Standard input/output header
void ClickLMB() // [3] Function to press the left mouse button
{
INPUT input; // [4] Struct for holding the input data
input.type = 0; // [4] Set type to mouse
input.mi.dwFlags = 2; // [5] Set action to left down
input.mi.mouseData = 0; // [5] Set data to none
input.mi.time = 0; // [5] Set time to current
SendInput(1, &input, sizeof(INPUT)); // [6] Make the input
input.mi.dwFlags = 4; // [5] Set action to left up
Sleep(10); // [1] Wait 10 milliseconds
SendInput(1, &input, sizeof(INPUT)); // [6] Make the input
}
int main() // [7] Main entry point
{
printf("Hold F10 to click\n"); // [2] Display some text
printf("Press F12 to stop the program\n"); // [2] Display some text
while (1) // [11] Infinite loop
{
if (GetAsyncKeyState(VK_F10)) // [8][9][10] Test if the F10 key was pressed
{
ClickLMB(); // [3] Click the left mouse button
}
if (GetAsyncKeyState(VK_F12)) // [8][9][10] Test if the F12 key was pressed
{
break; // [11] Leave the loop
}
}
return 0; // [7] Exit normaly
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment