Problem with Windows Key in KEY_DOWN OnEvent

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

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

Problem with Windows Key in KEY_DOWN OnEvent

Post by jpuziano » Mon Feb 25, 2008 1:54 am

Hi Marcus,
  • Version 10.021 23/02/2008
    - Added Windows Key to KEY_DOWN OnEVent ( 8 )
Thanks for that, however there seems to be a problem; try this macro (I am running XP SP2):

Code: Select all

// key code for the multiply key * on the numeric keypad
// VK_MULTIPLY (106)
// Multiply key

//numeric keypad multiply key * and modifier: Windows Key pressed simultaneously
OnEvent>KEY_DOWN,VK106,8,KeyPress_multiply_with_windows_key

//numeric keypad multiply key * and no modifier
OnEvent>KEY_DOWN,VK106,0,KeyPress_multiply_no_modifier

Let>Exit_Flag=0

Label>start
Wait>1
If>Exit_Flag=1,end
Goto>start

SRT>KeyPress_multiply_with_windows_key
  MDL>multiply key was pressed with the Windows Key
END>KeyPress_multiply_with_windows_key

SRT>KeyPress_multiply_no_modifier
  Let>Exit_Flag=1
  MDL>multiply key was pressed alone - exit flag set to 1
END>KeyPress_multiply_no_modifier

Label>end
MDL>Exiting macro...
1 - When you press the Windows Key and the numeric keypad * key simultaneously, it does not sense that. Instead it sees the * key pressed alone... and in the case of this macro, exits.

2 - Pressing the numeric keypad * key all by itself does get recognized properly... however, why do we have to hold it down so long? If I just tap the key lightly, I hear a beep so I know the machine "saw" the keypress but OnEvent KEY_PRESS won't fire unless I hold the key down longer. When I assign a "Hot Key" to a macro, those are sensed immediately with the lightest of taps. Why can't OnEvent KEY_PRESS be as responsive?

Thanks for adding this by the way... nice to have the Windows Key as a modifier.
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
jpuziano
Automation Wizard
Posts: 1085
Joined: Sat Oct 30, 2004 12:00 am

Post by jpuziano » Mon Feb 25, 2008 5:25 am

Hi Marcus,

I found an old post from JRL about a problem with OnEvent KEY_DOWN: http://www.mjtnet.com/usergroup/viewtopic.php?p=18447
JRL wrote:Usually, when I use Onevent>KEY_DOWN with or without a modifier key (shift, alt, ctrl) all works well. But when I tried to setup two onevents for the same key one with a modifier and one without. I only got results from the one without the modifier key even when I used the modifier key.

...

After a fair amount of aggravation, I discovered that the order of the onevents in the script matters.

Hopefully this will save someone else some time.
Later,
Dick
This must be the same issue, I flipped the order of two OnEvent lines and things now work better.

A fix was done for the original problem...
JRL wrote:From this post
Beta 10 Build 002 is now available from registered downloads.

Fixes/Changes since 001:
- Added more hotkey options to macro properties.
- Debugger will auto-scroll when stepping to keep debug line roughly central in editor
- Fixed: 0 for modifier key in KEY_DOWN event was treated as NONE or ANY, not just NONE
Thank you. I've tested and this issue appears to be fixed for version 10 beta. The workaround will continue to be valid for versions 8 and 9.
Marcus, is a further fix possible so the new "Windows Key" modifier does not have this same problem?

Thanks and take care
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
JRL
Automation Wizard
Posts: 3532
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Mon Feb 25, 2008 5:40 am

jpuziano,
I was just about to post that same link to address your original question 1. If you reorder the onevents both work properly which is the same situation I was experiencing with the other modifier keys.

For your question 2. Try setting the wait in the start loop to a smaller value. Your sample has the wait at 1 second. An onevent will not evoke during a wait. If I set the wait to 0.01 I get an immediate response to the key press.

Hope this is helpful,
Dick

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

Post by jpuziano » Mon Feb 25, 2008 6:34 am

JRL wrote:jpuziano,
I was just about to post that same link to address your original question 1. If you reorder the onevents both work properly which is the same situation I was experiencing with the other modifier keys.
Yes, same situation, reordering solved it... but rather than everyone having to remember the need for this workaround, I hope Marcus can apply the same magic when he fixed the original problem... to take care of the new Windows Key modifier as well.
JRL wrote:For your question 2. Try setting the wait in the start loop to a smaller value. Your sample has the wait at 1 second. An onevent will not evoke during a wait. If I set the wait to 0.01 I get an immediate response to the key press.
I changed the Wait to 0.001 and response time improved dramatically... it works 9 out of 10 times now... but occasionally, I can hold down the Windows Key and tap the * key and it does not see it. Again, I know the machine has seen it because it makes a sound... but the OnEvent does not fire.

Again, I wish OnEvent was "interrupt driven" or "windows event driven" so that each and every single time I tap that key, if the machine sees it, the event will fire. Marcus, any hope of that happening? Hot Keys can do this... I cannot understand why OnEvent can't... or wasn't designed to.

Another question, what is the smallest unit of time that Macro Scheduler understands for a Wait> statement? It doesn't say in the Help File. At some time in the past, I know that values less than a second became useable but what is the smallest unit of time it handle? I just used Wait>0.000000000001 and it didn't complain. How low can we go?
JRL wrote:Hope this is helpful,Dick
Helpful as always JRL, thanks again. And thanks to you too Marcus... thanks for listening.
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
JRL
Automation Wizard
Posts: 3532
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Mon Feb 25, 2008 1:31 pm

jpuziano wrote:what is the smallest unit of time that Macro Scheduler understands for a Wait> statement?
Running the following test, I'd say you can set dwell to any number but the wait> doesn't wait for anything less than 0.01 seconds. Try it and see for yourself. Set the variable dwell to different values and see what you get for total time.

Code: Select all

Let>dwell=0.01
VBSTART
VBEND
VBEval>timer,starttime
Let>kk=0
Repeat>kk
Add>kk,1
Message>kk
Wait>dwell
until>kk=1000

Label>EOF
VBEval>timer,endtime
Let>totaltime=%endtime%-%starttime%
MDL>totaltime

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

Post by Marcus Tettmar » Mon Feb 25, 2008 1:36 pm

Actually the smallest value that will do anything is 0.001

Why? Because internally the command has to convert to round milliseconds. 0.001 is 1 millisecond. So that's the smallest unit you can wait for.

Whether you'll notice any difference between 0.001 or 0.01 is debatable, but technically, 0.001 is smallest number. Anything smaller will round to zero.
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