This App is No Longer Maintained. Visit the Replacement at StrokesPlus.net

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

 All Forums
 Lua Scripts
 General Action Scripts
 acSendKeys problem
 Forum Locked
 Printer Friendly
Author Previous Topic Topic Next Topic  

TheMist

14 Posts

Posted - 12/19/2012 :  17:50:44  Show Profile
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  Show Profile  Visit Rob's Homepage
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
2615 Posts

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

Rob

USA
2615 Posts

Posted - 12/19/2012 :  18:07:39  Show Profile  Visit Rob's Homepage
...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
2615 Posts

Posted - 12/19/2012 :  18:34:33  Show Profile  Visit Rob's Homepage
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
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
2615 Posts

Posted - 12/20/2012 :  11:19:58  Show Profile  Visit Rob's Homepage
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
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
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
2615 Posts

Posted - 12/20/2012 :  12:59:14  Show Profile  Visit Rob's Homepage
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  
 Forum Locked
 Printer Friendly
Jump To:
StrokesPlus Forum © 2011-2018 Rob Yapchanyk Go To Top Of Page
Snitz Forums 2000