OnEvent> question

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
User avatar
JRL
Automation Wizard
Posts: 3532
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

OnEvent> question

Post by JRL » Wed Jul 16, 2008 2:18 pm

Is there a reason that OnEvent> does not detect the press of the Alt, Ctrl, Shift, LeftWin or RightWin keys when they are pressed alone? It will detect them in conjunction with another key such as Alt+A. But I can't get OnEvent> to detect the single press of, for example, the Alt key.

I included TAB in the following example because it will be detected.

Code: Select all

//Press Esc to close
OnEvent>KEY_DOWN,VK27,0,Quit
//Tab
OnEvent>KEY_DOWN,VK9,0,Test
//LeftWin
OnEvent>KEY_DOWN,VK91,0,Test
//RightWin
OnEvent>KEY_DOWN,VK92,0,Test
//Shift
OnEvent>KEY_DOWN,VK16,0,Test
//Ctrl
OnEvent>KEY_DOWN,VK17,0,Test
//Alt
OnEvent>KEY_DOWN,VK18,0,Test

Label>Loop
  Wait>0.01
Goto>Loop

SRT>Quit
  Exit>0
END>Quit

SRT>Test
Message>Ok
END>Test

User avatar
Bob Hansen
Automation Wizard
Posts: 2475
Joined: Tue Sep 24, 2002 3:47 am
Location: Salem, New Hampshire, US
Contact:

Post by Bob Hansen » Wed Jul 16, 2008 2:43 pm

It is not possible to monitor a keyboard activity unless it is sending a scan code. I suspect that those keys do not send a "scan" code.

They work locally on the keyboard to modify the scan code of any other keys that may be pressed while that key is down. So it is the other keys that send out a scan code that has been modified.
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

User avatar
JRL
Automation Wizard
Posts: 3532
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Wed Jul 16, 2008 2:47 pm

Hi Bob,

I had considered that and it might be the case with Ctrl and Shift but Alt will typically set focus to an application's menu and the left or right winkey will call up the windows start menu. So I don't buy that argument in those three cases.

Me_again
Automation Wizard
Posts: 1101
Joined: Fri Jan 07, 2005 5:55 pm
Location: Somewhere else on the planet

Post by Me_again » Wed Jul 16, 2008 2:58 pm

Left and right CTRL send scan codes too.

User avatar
JRL
Automation Wizard
Posts: 3532
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Wed Jul 16, 2008 3:19 pm

I found a way around it. Simply add the OnEvent> modifier that matches the key being pressed. In other words for the shift key use the VK code
16 and the modifier 1. Basically you're asking to detect when the Shift+Shift combination is pressed. OnEvent> will then successfully detect a single shift key press.

Thanks for your replies.

Code: Select all

//Press Esc to close
OnEvent>KEY_DOWN,VK27,0,Quit
//Tab
OnEvent>KEY_DOWN,VK9,0,Test
//LeftWin
OnEvent>KEY_DOWN,VK91,8,Test
//RightWin
OnEvent>KEY_DOWN,VK92,8,Test
//Shift
OnEvent>KEY_DOWN,VK16,1,Test
//Ctrl
OnEvent>KEY_DOWN,VK17,2,Test
//Alt
OnEvent>KEY_DOWN,VK18,3,Test

Label>Loop
  Wait>0.01
Goto>Loop

SRT>Quit
  Exit>0
END>Quit

SRT>Test
Message>Ok
END>Test

Me_again
Automation Wizard
Posts: 1101
Joined: Fri Jan 07, 2005 5:55 pm
Location: Somewhere else on the planet

Post by Me_again » Wed Jul 16, 2008 3:25 pm

Little utilty here to display key codes.

User avatar
Bob Hansen
Automation Wizard
Posts: 2475
Joined: Tue Sep 24, 2002 3:47 am
Location: Salem, New Hampshire, US
Contact:

Post by Bob Hansen » Wed Jul 16, 2008 6:28 pm

So, my suspicion was wrong.
Sorry about that, but the good news is that you have a solution.

And we all have a new utility tool thanks to Me_again.
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

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