Ignore the shift key being held down

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Grasshopper
Posts: 4
Joined: 31 Oct 2020, 08:47

Ignore the shift key being held down

31 Oct 2020, 09:31

Hello, I'm new to AHK and am stuck on this one:

I'm using a programmable keypad to trigger AHK macros. Using the software provided with the keypad, I've assigned each key to Ctrl+F1, Ctrl+F2 etc and have defined macros in AHK for each of those key combinations. I have to use KeyWait, Control to make this work because without it the script sometimes runs before the keypad releases the virtual control key,, which messes up the macro. This is how I have it set up, and it is working perfectly:

Code: Select all

^F1::
KeyWait, Control
(((macro here)))
return
I'm having trouble taking this one step further. I'd like to have a second layer of commands for the keypad buttons that run when I hold the shift key on the keyboard while pressing the keypad button. I can make it work by adding "+" and adding "KeyWait, Shift", but I would need to be able to use the macros consecutively without having to release the shift key every time. This code also works, but obviously you have to release shift every time before it executes:

Code: Select all

^+F1::
KeyWait, Control
KeyWait, Shift
(((secondary macro here)))
return
Is there a way that I can have a different macro run when I hold shift and press the keypad button assigned to Ctrl+F1, but do it in a way that the script ignores the fact that the keyboard shift key may or may not still be held down while the script is running and could be released in the middle of the script running? My thought would be to remove the "KeyWait, Shift" and somehow trick the computer into not acknowledging the keyboard shift key only for the duration of the script, but I'm not sure how to accomplish this or if there is a better way. Any advice on things I can try will be very much appreciated.
User avatar
mikeyww
Posts: 26885
Joined: 09 Sep 2014, 18:38

Re: Ignore the shift key being held down

31 Oct 2020, 10:01

There are various ways. Sending text can be done in Blind mode. You can also send Shift Up at any point.
^space::Send {Blind}{Ctrl up} allows Ctrl to be logically up even though it is physically down.
If you don't need to wait for the key release, then I'm not sure why you are having an issue or would need this, but it still might work.
Grasshopper
Posts: 4
Joined: 31 Oct 2020, 08:47

Re: Ignore the shift key being held down

01 Nov 2020, 22:18

Thanks, I tried that and it mostly works, but it looks like the fact that shift is being held down is randomly overriding the blind command. I have the following code for testing:

Code: Select all

^+F1::
KeyWait, Control
SendInput {Blind}{Shift Up}
SendInput Testing sending a string of text {Enter}
return
When I click it several times consecutively I get:
Testing sending a string of text
Testing sending a string of text
Testing sending a string of TEXT
Testing sending a string of text
Testing sending a string OF TEXT
Testing sending a string of text
TestinG SENDING A STRING OF TEXT
Testing sending a string of text

Is there a way to keep the shift key logically up for the duration of the script execution but then return it to reading the physical state of the shift key at the end of the script? The script does work if I release the shift key very quickly, so the issue is something to do with holding down the shift key. The point that the shift key re-engages is seemingly random.
User avatar
mikeyww
Posts: 26885
Joined: 09 Sep 2014, 18:38

Re: Ignore the shift key being held down

01 Nov 2020, 22:54

I don't know. Something strange is happening with your keypad. I could not reproduce your results with or without Blind, even when I held SHIFT down for the entire sequence.

You could try using Hotkey to disable SHIFT temporarily in your routine (can set a hotkey for Shift so that it only executes Return), though I don't know what the result would be with your hardware. SHIFT can also be remapped to a key that does nothing.

If your keypad uses a keyboard hook, then it may be conflicting with AHK. Does the keypad have a utility that you can uninstall?

Others here on the forum understand the keys more fully and may have advice for you.
Grasshopper
Posts: 4
Joined: 31 Oct 2020, 08:47

Re: Ignore the shift key being held down

20 Nov 2020, 12:30

Thank you for your help. You are right that it is definitely something odd about my keypad since when I tested it using the key combinations on the keyboard it worked correctly. I experimented with several things and ended up using "BlockInput" and running the script as an administrator. Working well for me so far.
hotkeyguy
Posts: 170
Joined: 11 Oct 2014, 12:22

Re: Ignore the shift key being held down

01 Dec 2021, 12:57

I have the same problem. Shift is pressed, and I'm using SendInput for my text. The text shouldn't be altered by Shift, just send as is. I tried {Blind}{Shift Up}, the text is still all uppercase!
User avatar
mikeyww
Posts: 26885
Joined: 09 Sep 2014, 18:38

Re: Ignore the shift key being held down

01 Dec 2021, 13:05

All of the following worked for me.

Code: Select all

^+F1::SendInput Testing sending a string of text {Enter}

^+F2::
KeyWait, Control
KeyWait, Shift
SendInput Testing sending a string of text {Enter}
Return

^+F3::
KeyWait, Control
SendInput Testing sending a string of text {Enter}
KeyWait, Shift
Return

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: RandomBoy, Rohwedder, ruespe and 382 guests