SendInput Is Not Releasing KeyState

Get help with using AutoHotkey and its commands and hotkeys
enteleform
Posts: 7
Joined: 26 Feb 2016, 01:14
GitHub: enteleform

SendInput Is Not Releasing KeyState

09 Mar 2016, 18:40

I'm attempting to remap my PrintScreen button as RWin so that I can use hotkeys ambidextrously.
PrintScreen::Rwin does not work.

In my final script, I would like all modifiers & non-alphanumeric keys to work.
EG:
Shift+PrintScreen+A == Shift+RWin+A
Ctrl+Alt+PrintScreen+Enter == Ctrl+Alt+RWin+Enter

Even attempting this without modifiers, I am running into an issue.

If I run the following code, the initial action is accurate ( EG: PrintScreen+E shows Window Explorer ). However, RWin Up is not working.
I have another command that uses Win+LButton and if I click after running the PrintScreen code, the other function will execute as if I am holding down Win.

Code: Select all

	PrintScreen::

	Input, pressedKey, L1 T1.5

	If ( ErrorLevel = "Timeout" )
		return

	SendInput % "{ RWin Down } + { " pressedKey " }" "{ RWin Up }"
Last edited by enteleform on 10 Mar 2016, 07:41, edited 2 times in total.
wizardzedd
Posts: 319
Joined: 23 Jan 2016, 23:03

Re: SendInput Is Not Releasing KeyState

09 Mar 2016, 21:19

why doesn't PrintScreen::RWin work?

Code: Select all

PrintScreen::RWin
^#f:: MsgBox Hello!
lexikos
Posts: 7088
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

Re: SendInput Is Not Releasing KeyState

09 Mar 2016, 21:33

I think your SendInput syntax is wrong for what you're trying to do.
  • PrintScreen:: will only activate if you are not holding any modifier keys such as Shift, so I think you're not trying to send RWin & Shift. In that case, I guess you used "+" to combine RWin and pressedKey, but that's not how it works. + is the modifier symbol for Shift.
  • Spaces outside braces are interpreted literally, equivalent to {Space}, so {RWin Down} + {whatever}{RWin up} is the same as {RWin Down}{Space}{Shift down}{Space}{Shift up}{whatever}{RWin up}.
To support other combinations of modifier keys, you will need to add * (*PrintScreen::) and {Blind} (SendInput % "{Blind}...).

I think the Input approach mightn't work very well with key combinations or multiple hotkey activations for a single press of PrintScreen (i.e. holding it down). Also, it won't require you to hold PrintScreen while pressing the other key, but maybe that's okay.

PrintScreen::Rwin should work, and it does for me. It already implicitly uses * and {Blind}.

This also works for me, and retains normal PrintScreen functionality (at least on Windows 7) if you press and release PrintScreen on its own:

Code: Select all

SendMode Input
*PrintScreen::
	Send {Blind}{RWin down}
	return
*PrintScreen up::
	if (A_PriorKey = "PrintScreen")
		Send {PrintScreen}
	Send {Blind}{RWin up}
	return
However, it might need tweaking on Windows 10, where I think RWin+PrintScreen has a different function to just PrintScreen.

I've used exactly the same pattern to turn AppsKey into a substitute RWin (since it is in exactly the right place on some keyboards) while retaining its context-menu function.
enteleform
Posts: 7
Joined: 26 Feb 2016, 01:14
GitHub: enteleform

Re: SendInput Is Not Releasing KeyState

10 Mar 2016, 07:11

──────────
Replies
──────────
lexikos wrote:[*]PrintScreen:: will only activate if you are not holding any modifier keys such as Shift
I was just trying to get the initial command working before implementing modifiers.

lexikos wrote:I guess you used "+" to combine RWin and pressedKey
Looks like I skimmed through an example @ the AHK docs too fast :crazy:

lexikos wrote:PrintScreen::Rwin should work, and it does for me.
I just tried it again, and it's working this time around. May have been an issue with the build process @ SublimeText.

lexikos wrote:This also works for me, and retains normal PrintScreen functionality if you press and release PrintScreen on its own:

Code: Select all

*PrintScreen::
	Send {Blind}{RWin down}
	return
*PrintScreen up::
	if (A_PriorKey = "PrintScreen")
		Send {PrintScreen}
	Send {Blind}{RWin up}
This is awesome :thumbup:. It's actually the exact end result I was looking for!
I tried using * & {Blind} before but I guess I structured it incorrectly.


──────────────────
Modifications
──────────────────

I've implemented Windows Snipping Tool, as it has much greater functionality than the default PrintScreen function:
  • it allows area clipping & full screen capture
  • it automatically copies the screenshot, so it can be directly pasted into a graphic editor
  • it allows saving at arbitrary locations, rather than being limited to a single default directory
The following code allows:
  1. A single press of PrintScreen to clip a selected area of the screen
  2. A double press of PrintScreen to clip the entire screen area
  3. PrintScreen as RWin + Optional Modifiers + Any Key
───────
Issue
───────

I'm running into a minor issue, which is detailed in the code & GIFs below.
I've managed to achieve the desired functionality, but I had to implement a workaround which results in a Start Menu artifact.

:?: Do you have any suggestions? :?:

Also: Can this thread be moved to Scripts and Functions once it's working smoothly?

───────
Code
───────
───────────────────────
Visual Reference
───────────────────────

RWin Functionality:

Image

Screen Clipping:

Image

Screen Capture ( Issue ):

Image
lexikos
Posts: 7088
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

Re: SendInput Is Not Releasing KeyState

11 Mar 2016, 00:14

Sending RWin up without having pressed any other key since RWin down will cause the Start menu to appear. You can avoid that by sending some other key. Send {PrintScreen} serves this purpose, but you can just send a key that does nothing instead.
Also: Can this thread be moved to Scripts and Functions once it's working smoothly?
It would be better to re-post your script with proper description etc. without discussion of problems that you've solved.
enteleform
Posts: 7
Joined: 26 Feb 2016, 01:14
GitHub: enteleform

Re: SendInput Is Not Releasing KeyState

14 Mar 2016, 15:29

lexikos wrote:You can avoid that by sending some other key. Send {PrintScreen} serves this purpose, but you can just send a key that does nothing instead.
I didn't get that when I first read it. I actually finished the script with some other workarounds. Just posted it at: Enhanced PrintScreen [ Clip | Capture ] with RWin Passthrough

But I think you were saying rather than just sending RWin Up, maybe send something like:
F24 Down, RWin Up F24 Up ?
lexikos
Posts: 7088
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

Re: SendInput Is Not Releasing KeyState

14 Mar 2016, 19:57

Yes, except that {F24 Down} would leave F24 in the pressed state...

{vk07} is less likely to do anything unwanted than F24. It is an unassigned keycode according to the Windows SDK.

AutoHotkey uses {Ctrl} internally by default, but sometimes it has unwanted effects, like triggering Google Desktop (hence #MenuMaskKey).
enteleform
Posts: 7
Joined: 26 Feb 2016, 01:14
GitHub: enteleform

Re: SendInput Is Not Releasing KeyState

14 Mar 2016, 20:53

lexikos wrote:{vk07} is less likely to do anything unwanted than F24. It is an unassigned keycode according to the Windows SDK.
Just implemented Send, {vk07}{RWin Up}, & it works great.

Thanks for your help! :thumbup:

Return to “Ask For Help”

Who is online

Users browsing this forum: c7aesa7r, mikeyww, nanowiz, omar and 41 guests