OnEvent Failure

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
armsys
Automation Wizard
Posts: 1108
Joined: Wed Dec 04, 2002 10:28 am
Location: Hong Kong

OnEvent Failure

Post by armsys » Thu Jan 27, 2011 10:09 am

I experiment with the following code.
Pressing ESC won't trigger Subroutine DoExit.
Please help. Thanks.

Code: Select all

OnEvent>KEY_DOWN,VK_ESCAPE,0,DoExit
Let>k=1
While>k<1000>Ok
  Wait>.5
Endwhile
SRT>DoExit
  Exit
END>DoExit

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Thu Jan 27, 2011 10:16 am

Your first line should be:

OnEvent>KEY_DOWN,VK27,0,DoExit
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

armsys
Automation Wizard
Posts: 1108
Joined: Wed Dec 04, 2002 10:28 am
Location: Hong Kong

Post by armsys » Thu Jan 27, 2011 10:27 am

Of course, once you leak the secret code, it works brilliantly.
My VK_ESCAPE was copied directly from http://www.mjtnet.com/vkcodes.htm.
Thanks for your quick help.

armsys
Automation Wizard
Posts: 1108
Joined: Wed Dec 04, 2002 10:28 am
Location: Hong Kong

Post by armsys » Thu Jan 27, 2011 10:28 am

Where could we locate the latest complete list VK codes?

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Thu Jan 27, 2011 10:30 am

Secret? Here's what the help file says:
WaitKeyDown pauses execution until the specified key is pressed. For an ordinary character key specifiy the character of the key. For other keys use the virtual key code preceeded by VK:

...

WaitKeyDown>VK101 - waits for virtual key code 101 (Numpad 5) to be pressed.
Emphasis mine.

Then it links to the page you quote which shows for VK_ESCAPE:

VK_ESCAPE (27)
ESC key

So the number you need to put after VK is 27.

So not really a secret :-)
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Thu Jan 27, 2011 10:51 am

A search on Microsoft reveals:

http://msdn.microsoft.com/en-us/library ... s.85).aspx

According to the date at the bottom it was built on 1st Dec 2010. So I guess it's pretty current.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

armsys
Automation Wizard
Posts: 1108
Joined: Wed Dec 04, 2002 10:28 am
Location: Hong Kong

Post by armsys » Thu Jan 27, 2011 10:38 pm

Marcus,
Thanks for updating your VK source link.
Nonetheless, it still requires some imagination to translate between Microsoft's VK list and the actual coding in Macro Scheduler. Your last post leaks the missing link.
For example, in both http://msdn.microsoft.com/en-us/library/dd375731 and http://www.mjtnet.com/vkcodes.htm, Esc is expressed as VK_ESCAPE. In actual Macro Scheduler scirpt, it should code as VK27.

User avatar
jpuziano
Automation Wizard
Posts: 1085
Joined: Sat Oct 30, 2004 12:00 am

Post by jpuziano » Fri Jan 28, 2011 2:00 am

armsys wrote:Nonetheless, it still requires some imagination to translate between Microsoft's VK list and the actual coding in Macro Scheduler. Your last post leaks the missing link.
For example, in both http://msdn.microsoft.com/en-us/library/dd375731 and http://www.mjtnet.com/vkcodes.htm, Esc is expressed as VK_ESCAPE. In actual Macro Scheduler scirpt, it should code as VK27.
Not that much imagination required actually... as long as you remember... the Help File is your friend.
Help File entry for OnEvent wrote:OnEvent

OnEvent>EventType,EventParm,ExtraParm,Subroutine

Not supported in Macro Scheduler Lite.

Establishes an event handler. When the event occurs the script branches to the specified Subroutine.

...
Tons of good stuff here, please read the actual Help File, it will help... honest
...

Example

OnEvent>WINDOW_OPEN,Notepad*,2,DoNotepad
OnEvent>WINDOW_NOTOPEN,Notepad*,2,DoNotepadNotOpen
OnEvent>WINDOW_NEWACTIVE,0,0,DoNewWindow
OnEvent>KEY_DOWN,VK32,3,KeyPress

Label>start
Wait>1
If>NotepadOpen=1
Message>Notepad is open
Else
Message>Notepad is not open
Endif
Goto>start

SRT>DoNotepad
Let>NotepadOpen=1
END>DoNotepad

SRT>DoNewWindow
GetActiveWindow>title,x,y
MessageModal>New window: %title%
END>DoNewWindow

SRT>DoNotepadNotOpen
Let>NotepadOpen=0
END>DoNotepadNotOpen

SRT>KeyPress
MessageModal>ALT+Space was pressed
END>KeyPress
As you can see, the code example uses VK32 while in the sources you mention, its called VK_SPACE.

There you go Marcus, don't say I don't stick up for the Help File. :)
jpuziano

Note: If anyone else on the planet would find the following useful...
[Open] PlayWav command that plays from embedded script data
...then please add your thoughts/support at the above post - :-)

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Fri Jan 28, 2011 8:58 am

mtettmar wrote:Secret? Here's what the help file says:
WaitKeyDown pauses execution until the specified key is pressed. For an ordinary character key specifiy the character of the key. For other keys use the virtual key code preceeded by VK:

...

WaitKeyDown>VK101 - waits for virtual key code 101 (Numpad 5) to be pressed.
Emphasis mine.

Then it links to the page you quote which shows for VK_ESCAPE:

VK_ESCAPE (27)
ESC key

So the number you need to put after VK is 27.

So not really a secret :-)
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts