Author |
Topic |
|
TheMist
14 Posts |
Posted - 12/19/2012 : 17:50:44
|
Hi Rob, thanks for a great program!
I am trying to send some text to current window on WIN+J hotkey. like this:
acSendKeys("PPPPP~")
But unfortunately the S+ start sending my string before I release the WIN key. Instead of my string in Notepad I see windows reaction on WIN+P key combination. I have workaround: acDelay(1000) --give 1 sec to release hotkey acSendKeys("PPPPP~")
It works, but sometimes 1 sec delay is annoying, sometimes is not enough. Cold the script be executed on keyUP event?
|
|
Rob
USA
2615 Posts |
Posted - 12/19/2012 : 17:58:33
|
Haven't tested it out a bunch, but this seemed to work:acConsumePhysicalInput(1)
acSendWinUp()
acSendKeys("PPPPP~")
acConsumePhysicalInput(0) Basically, it tells S+ to eat all input (so it never makes it to any program), send the WinUp event (so the foreground window thinks the Win key was released), then send the keys, and finally allow input to resume.
Never forget to call acConsumePhysicalInput(0) or you'll pretty much have to shutdown the computer and reboot :-)
(moved topic since it's not technically a bug...but I'll still mull this over to see if it makes sense to update the code, assuming it doesn't negatively affect anything else) |
|
|
Rob
USA
2615 Posts |
Posted - 12/19/2012 : 18:05:14
|
Actually, just this works:acSendWinUp()
acSendKeys("PPPPP~") |
|
|
Rob
USA
2615 Posts |
Posted - 12/19/2012 : 18:07:39
|
...and if you want to be able to fire the hotkey again without having to release the Win key first, you can do this:acSendWinUp()
acSendKeys("PPPPP~")
acSendWinDown() (although it does seem to cause the start menu to pop up after you let go of the Win key after multiple hotkey presses..but I'll leave it here anyway) |
|
|
Rob
USA
2615 Posts |
Posted - 12/19/2012 : 18:34:33
|
To elaborate on why it's not a bug, as well as why it can't be fired on key_up:
S+ registers a hot key with Windows. As soon as the hotkey is pressed, Windows sends a WM_HOTKEY message to the S+ message pump, which responds by firing your script. S+ isn't hooking the keys to monitor all key presses, waiting for a hot key combination to be pressed.
While the outcome is definitely counter-intuitive for your usage, Notepad (or any app) is just responding to the key states; e.g. the Win key is down and a P was pressed. So in these instances, we'll have to use something like what I've posted above to handle things accordingly. |
|
|
TheMist
14 Posts |
Posted - 12/20/2012 : 11:15:13
|
quote: Originally posted by Rob
Actually, just this works:acSendWinUp()
acSendKeys("PPPPP~")
I've tried this already before asking you, it does not work on my Windows7 64bit.
But the ConsumePhysicalInput sample works perfect Thank you.
|
|
|
Rob
USA
2615 Posts |
Posted - 12/20/2012 : 11:19:58
|
Hmm, worked on my Win7 64 config; but I'm glad at least one of them worked for you!
acConsumePhysicalInput can be very useful when trying to simulate input, especially when moving the mouse or clicking, to ensure the actual keyboard/mouse input doesn't interfere with the action. |
|
|
TheMist
14 Posts |
Posted - 12/20/2012 : 12:33:58
|
Well ... it does not work if there is an "L" in the string :'(
acConsumePhysicalInput(1) acSendWinUp() acSendKeys("PLpl~") acConsumePhysicalInput(0) |
|
|
TheMist
14 Posts |
Posted - 12/20/2012 : 12:44:06
|
It is not a big deal, I've switched to CTRL+ALT combo instead of WIN key in hotkey.
|
|
|
Rob
USA
2615 Posts |
Posted - 12/20/2012 : 12:59:14
|
Which makes sense, Win+L is a combination recognized at the kernel level, so there's no getting around that within the application space. |
|
|
|
Topic |
|