{"id":2292,"date":"2014-03-27T09:59:05","date_gmt":"2014-03-27T09:59:05","guid":{"rendered":"http:\/\/www.mjtnet.com\/blog\/?p=2292"},"modified":"2014-03-27T09:59:05","modified_gmt":"2014-03-27T09:59:05","slug":"why-doesnt-shift-esc-stop-my-compiled-macros","status":"publish","type":"post","link":"https:\/\/www.mjtnet.com\/blog\/2014\/03\/27\/why-doesnt-shift-esc-stop-my-compiled-macros\/","title":{"rendered":"Why doesn&#8217;t SHIFT-ESC stop my compiled macros?"},"content":{"rendered":"<p>You might find that when you run a compiled macro and you also have Macro Scheduler running, Shift-Esc &#8211; the default stop key sequence &#8211; doesn&#8217;t stop the compiled macro.<\/p>\n<p>This is because the stop key sequence is a system wide hot key.  And system wide hot keys can only be registered for use by one application at a time.  So if Macro Scheduler is already running when you start your .exe the .exe is unable to register Shift-Esc because Macro Scheduler already has it.<\/p>\n<p>Of course when you deploy your .exe to people who don&#8217;t already have Macro Scheduler &#8211; which is usually the case &#8211; there won&#8217;t be any problem because Macro Scheduler won&#8217;t be running and so your .exe is able to register the Shift-Esc hot key.<\/p>\n<p>But what if you want to define your own stop hot key, or you want to give your users the option of setting it?  Well what you need is a KEY_DOWN event handler:<\/p>\n<pre class=\"brush: macroscript\">\/\/CTRL-Z is stop key\r\nOnEvent>KEY_DOWN,VK90,2,doExit\r\nLet>paused=FALSE\r\n\r\n\/\/sample code here ...\r\nWait>20\r\nMessageModal>hello\r\n\r\nSRT>doExit\r\n   Exit>0\r\nEND>doExit<\/pre>\n<p>Here we have set up a key down event handler for CTRL+Z.  VK90 is Z and 2 is the modifier key for CTRL.  See the <a href=\"http:\/\/www.mjtnet.com\/manual\/index.html?onevent.htm\">OnEvent help topic<\/a> and <a href=\"http:\/\/www.mjtnet.com\/vkcodes.htm\">Virtual Key Codes List<\/a>.<\/p>\n<p>The event handler basically sets up a concurrent thread that is running all the while the main script is running.  This allows it to respond to events such as this KEY_DOWN event.  So when you hit the specified key sequence &#8211; in this case CTRL+Z, the doExit subroutine runs and all that does is call the Exit function which terminates the script.<\/p>\n<p>You could be smarter and ask the user if he really means he wants to exit:<\/p>\n<pre class=\"brush: macroscript\">SRT>doExit\r\n   Ask>Are you sure you want to exit?,ynExit\r\n   If>ynExit=YES\r\n      Exit>0\r\n   Endif\r\nEND>doExit<\/pre>\n<p>When you compile the macro there is an option to disable the standard Shift-Esc sequence.  So you could do that to completely replace the stop key system with your own custom one using your OnEvent.<\/p>\n<p>Consider an INI file and possibly another config script using a custom dialog to allow the user to set his own stop key sequence.  Other apps could already be using it.  My CTRL+Z example is probably not ideal as although it is used in Linux to suspend the current process it is usually the short cut for Undo in Windows.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>You might find that when you run a compiled macro and you also have Macro Scheduler running, Shift-Esc &#8211; the default stop key sequence &#8211; doesn&#8217;t stop the compiled macro. This is because the stop key sequence is a system wide hot key. And system wide hot keys can only be registered for use by [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[4,6],"tags":[],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/www.mjtnet.com\/blog\/wp-json\/wp\/v2\/posts\/2292"}],"collection":[{"href":"https:\/\/www.mjtnet.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.mjtnet.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.mjtnet.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.mjtnet.com\/blog\/wp-json\/wp\/v2\/comments?post=2292"}],"version-history":[{"count":3,"href":"https:\/\/www.mjtnet.com\/blog\/wp-json\/wp\/v2\/posts\/2292\/revisions"}],"predecessor-version":[{"id":2296,"href":"https:\/\/www.mjtnet.com\/blog\/wp-json\/wp\/v2\/posts\/2292\/revisions\/2296"}],"wp:attachment":[{"href":"https:\/\/www.mjtnet.com\/blog\/wp-json\/wp\/v2\/media?parent=2292"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.mjtnet.com\/blog\/wp-json\/wp\/v2\/categories?post=2292"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.mjtnet.com\/blog\/wp-json\/wp\/v2\/tags?post=2292"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}