Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <windows.h>
- /*
- Code grabbed from http://www.cplusplus.com/forum/lounge/17053/
- I altered it to make it work with the middle click as it's a convinient key
- */
- bool KeyIsPressed (unsigned char k)
- {
- USHORT status = GetAsyncKeyState(k);
- return (((status & 0x8000) >> 15) == 1) || ((status & 1) == 1);
- }
- int WINAPI WinMain (HINSTANCE hInst, HINSTANCE P, LPSTR CMD, int nShowCmd)
- {
- char k = 0x45; // 0x45 = E, 0x50 = P; WM_RBUTTONDOWN = Middle click
- while (true) {
- INPUT Input= {0}; // Create our input.
- Input.type = INPUT_MOUSE;
- while ( !KeyIsPressed (k) ) { Sleep (100); }
- while ( KeyIsPressed (k) ) {}
- while ( !KeyIsPressed (k) ) {
- // Let input know we are using the mouse.
- Input.mi.dwFlags = MOUSEEVENTF_LEFTDOWN; // We are setting left mouse button down.
- SendInput( 1, &Input, sizeof(INPUT) ); // Send the input.
- ZeroMemory( &Input, sizeof(INPUT) ); // Fills a block of memory with zeros.
- Input.mi.dwFlags = MOUSEEVENTF_LEFTUP; // We are setting left mouse button up.
- SendInput( 1, &Input, sizeof(INPUT) ); // Send the input.
- Sleep (10);
- }
- while ( KeyIsPressed (k) ) {}
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment