1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
|
#include<windows.h> // define windows
#ifndef VK_OEM_PERIOD // if the full-stop (period) key is not defined
#define VK_OEM_PERIOD 0xBE // define it
#endif // end definition
#ifndef VK_OEM_COMMA // if the comma key is not defined
#define VK_OEM_COMMA 0xBC // define it
#endif // end definition
#ifndef VK_BACK // if the backspace key is not defined
#define VK_BACK 0x08 // define it
#endif // end definition
HWND hwnd_ext; // define the external window's handle
int main() // main function
{
hwnd_ext=FindWindow(NULL,"app"); // set the handle to the window with the title "app", change this as necessary
if(hwnd_ext==NULL) // if the window does not exist
{
if(MessageBox(NULL,"The Application Window Is Not Open\nClick \"OK\" once it is open\nClick cancel to exit","Error",1)==2) // give an "OK" "Cancel" box
{
return 0; // if cancel, end the program
}
main(); // if it is okay, check again for the window (this might cause a stack overflow if you press "OK" enough... LOTS of times ;)
}
while(true) // we've reached our main program loop, while true (infinite loop)
{
if(GetAsyncKeyState(VK_OEM_PERIOD)) // get the key state of the full-stop (period) key, if it is true
{
if(GetForegroundWindow()==hwnd_ext) // & the foreground (active) window is our message box
{
keybd_event(VK_OEM_PERIOD,0x45,KEYEVENTF_KEYUP,0); // send the input for key up on the full-stop (period)
keybd_event(VK_BACK,0x45,0,0); // send backspace (delete the fullstop)
keybd_event(VK_OEM_COMMA,0x45,0,0); // send comma
}
}
Sleep(1); // sleep for 1 millisecond, this should stop CPU usage going huge
}
return 0; // end of program
}
// references
// keybd_event - http://msdn.microsoft.com/en-us/library/ms646304(VS.85).aspx
// GetAsyncKeyState - http://msdn.microsoft.com/en-us/library/ms646293(VS.85).aspx
// FindWindow - http://msdn.microsoft.com/en-us/library/ms633499.aspx
|