1: void toggler()
2: {
3: bool toggle=FALSE;
4: if (RegisterHotKey(NULL, 1, MOD_ALT|MOD_NOREPEAT, 0x42)) // B
9: {
10: cout << "Hotkey Registered" << endl;
11: }
12:
13: MSG msg = {0};
14:
15: while(1)
16: {
17: if(toggle==TRUE)
18: {
19: Sleep(500);
20: //<CODE GOES HERE>
21: }
22: else
23: Sleep(500);
24: while (PeekMessage(&msg, NULL, 0, 0, 1) != 0)
25: {
26: toggle = !toggle;
27: }
28: }
29: }
Lines 7/8 set the hotkey options, this has MOD_ALT and MOD_NOREPEAT so it doesn't spam the hotkey when I press it. 0x42 is the VK key code, which you can find here:
https://msdn.microsoft.com/en-us/library/windows/desktop/dd375731(v=vs.85).aspx
Press once to toggle it on, again to switch it off. Makes auto-clickers, for example, much easier than having to run the program every time.
Thursday, March 10, 2016
C++ Hotkey Toggle Framework
Haven't posted in a while. Been using this for a lot of game bots lately, just a simple hotkey toggle in C++.
Subscribe to:
Comments (Atom)