EXEs and Hotkeys
Related HelpFile Links : OnEvent
Something that comes up now and then is whether or not compiled Macro Scheduler macros can respond to hot-keys. Macro Scheduler itself lets you assign system-wide hot-keys to macros so that when you hit that key combination, no matter where you are in Windows, the macro will be fired.
Some people want to be able to distribute compiled macros (EXEs) to their friends and colleagues and have those EXEs respond to hot-keys in the same way. Something has to be running in order to listen for the hot-key and act on it. In the case of regular old Macro Scheduler that is Macro Scheduler itself. So how do we achieve it with a compiled macro?
Method 1 - make the EXE itself listen for the hot-key:
Use OnEvent to create a KEY_DOWN event handler to watch for the hot-key sequence:
OnEvent>KEY_DOWN,G,5,DoMacro Label>Idle_Loop Wait>0.02 Goto>Idle_Loop SRT>DoMacro .. Your Code Here .. End>DoMacro
The above will run indefinitely and whenever CTRL+ALT+G is pressed the macro code in the DoMacro subroutine will be fired. Clearly the macro has to be running all the time to listen for the hotkey - after all, something has to listen for it. So you could have the EXE run on startup by adding a shortcut to the Startup folder for example. Perhaps also compile the EXE with the /NOSYSTRAY and /HIDE parms so that the EXE is not visible when it runs. Or, better, compile with a custom icon so that your EXE has it's own fancy icon in the task bar.
See the documentation for the OnEvent function for more info on how to trap different keystrokes.
Method 2 - Let Windows do the work:
Don't tell me - all these years using Microsoft Windows and you didn't realise that keyboard shortcuts can be assigned to shortcuts?
So just create a desktop shortcut to your compiled EXE. Right click on the desktop shortcut and select properties. Notice the "Shortcut key" field. Press the keys you want to use to trigger the EXE. Press Ok. Sorted.