I would like to use RegisterHotKey to control the while loop below, without having to focus on the program. Pressing 1 toggles the bool mousetoggle, however I am not sure how to implement this with RegisterHotKey.
Below is the code in question. I would appreciate any advice or suggestions.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
char key = ' ';
while(key != VK_ESCAPE) // loop until user presses Escape
{
if(kbhit())
{
key = getch();
switch(key)
{
case'1':
mousetoggle = !mousetoggle; // invert bool var called mousetoggle
break;
}
}
if(mousetoggle) // when user presses '1', loop will enable
{
// code goes here
}
}
Because I see getch() there I suppose this is a console application? If yes, that won't work. RegisterHotKey() sends the WM_HOTKEY to a specific window or to the calling thread's message queue, and that requires that your program be a Windows GUI application, not a console application.