StrokesPlus Forum
                       
StrokesPlus Forum
Home | Profile | Register | Active Topics
Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Lua Scripts
 General Action Scripts
 acSendKeys problem
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

TheMist

14 Posts

Posted - 12/19/2012 :  17:50:44  Show Profile  Reply with Quote
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
2538 Posts

Posted - 12/19/2012 :  17:58:33  Show Profile  Visit Rob's Homepage  Reply with Quote
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)
Go to Top of Page

Rob

USA
2538 Posts

Posted - 12/19/2012 :  18:05:14  Show Profile  Visit Rob's Homepage  Reply with Quote
Actually, just this works:
acSendWinUp()
acSendKeys("PPPPP~")
Go to Top of Page

Rob

USA
2538 Posts

Posted - 12/19/2012 :  18:07:39  Show Profile  Visit Rob's Homepage  Reply with Quote
...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)
Go to Top of Page

Rob

USA
2538 Posts

Posted - 12/19/2012 :  18:34:33  Show Profile  Visit Rob's Homepage  Reply with Quote
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.
Go to Top of Page

TheMist

14 Posts

Posted - 12/20/2012 :  11:15:13  Show Profile  Reply with Quote
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.
Go to Top of Page

Rob

USA
2538 Posts

Posted - 12/20/2012 :  11:19:58  Show Profile  Visit Rob's Homepage  Reply with Quote
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.
Go to Top of Page

TheMist

14 Posts

Posted - 12/20/2012 :  12:33:58  Show Profile  Reply with Quote
Well ... it does not work if there is an "L" in the string :'(

acConsumePhysicalInput(1)
acSendWinUp()
acSendKeys("PLpl~")
acConsumePhysicalInput(0)
Go to Top of Page

TheMist

14 Posts

Posted - 12/20/2012 :  12:44:06  Show Profile  Reply with Quote
It is not a big deal,
I've switched to CTRL+ALT combo instead of WIN key in hotkey.
Go to Top of Page

Rob

USA
2538 Posts

Posted - 12/20/2012 :  12:59:14  Show Profile  Visit Rob's Homepage  Reply with Quote
Which makes sense, Win+L is a combination recognized at the kernel level, so there's no getting around that within the application space.
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
StrokesPlus Forum © 2011-2018 Rob Yapchanyk Go To Top Of Page
Snitz Forums 2000