Weird Modifier Behavior Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
skylr616
Posts: 9
Joined: 06 Nov 2017, 14:53

Weird Modifier Behavior

15 Jun 2021, 19:36

Does anyone know why the following sends Shift+7?

Code: Select all

^7::
Send, {ctrl}+{7}
Return
gregster
Posts: 9002
Joined: 30 Sep 2013, 06:48

Re: Weird Modifier Behavior

15 Jun 2021, 19:38

+ is the modifier symbol for the shift key, so this is expected behaviour. Your code sends Ctrl (presses and releases it), then sends a shifted 7.

What do you want to send?
skylr616
Posts: 9
Joined: 06 Nov 2017, 14:53

Re: Weird Modifier Behavior

15 Jun 2021, 20:03

Oh! That makes sense.

I'm trying to send 7, modified by ctrl (the same thing that triggers the hotkey).

When I try...

Code: Select all

^7::
Send, ^7
Return
...or...

Code: Select all

^7::
Send, ^{7}
Return
...it ignores the modifier and just sends 7.
User avatar
boiler
Posts: 16926
Joined: 21 Dec 2014, 02:44

Re: Weird Modifier Behavior

15 Jun 2021, 20:57

You could try:

Code: Select all

$^7::Send, {Ctrl down}7{Ctrl up}
skylr616
Posts: 9
Joined: 06 Nov 2017, 14:53

Re: Weird Modifier Behavior

17 Jun 2021, 18:13

I think I isolated the problem I'm having. When the modifier and the key are activated in separate SendInput events it ignores the CTRL modifier.

If I do something like:

Code: Select all

^7::
SendInput, {Ctrl Down}
Sleep, 25
SendInput, {7 Down}
Sleep, 25
SendInput, {7 Up}
Sleep, 25
SendInput, {Ctrl Up}
Return
It won't detect the CTRL modifier... as if the physical CTRL key is interfering with the SendInput CTRL. If I activate the hotkey and release the CTRL key on my keyboard very quickly it will work properly. I tried inserting a {Ctrl Up} at the start but the issue persists.
User avatar
boiler
Posts: 16926
Joined: 21 Dec 2014, 02:44

Re: Weird Modifier Behavior

17 Jun 2021, 21:18

Did you try the $ in front of the hotkey as I suggested to prevent the hotkey from triggering itself?
skylr616
Posts: 9
Joined: 06 Nov 2017, 14:53

Re: Weird Modifier Behavior

17 Jun 2021, 21:32

Yes, no change.
User avatar
mikeyww
Posts: 26885
Joined: 09 Sep 2014, 18:38

Re: Weird Modifier Behavior

17 Jun 2021, 22:02

Along the lines of boiler's comment, here is my go at this:

Code: Select all

$^7::Send ^7
But what does it accomplish?
User avatar
boiler
Posts: 16926
Joined: 21 Dec 2014, 02:44

Re: Weird Modifier Behavior

17 Jun 2021, 22:34

I was wondering the same thing, mikeyww. I figured it must just be some type of test that is a step towards something else, such as using ControlSend to send it to a particular inactive window. I also would be interested in hearing the actual purpose or end goal.
skylr616
Posts: 9
Joined: 06 Nov 2017, 14:53

Re: Weird Modifier Behavior

18 Jun 2021, 08:45

mikeyww wrote:
17 Jun 2021, 22:02
Along the lines of boiler's comment, here is my go at this:

Code: Select all

$^7::Send ^7
But what does it accomplish?
This works, but I lose the "performance and reliability" of SendInput and the fine-grain control over the time between and each and during each keystroke. I can use "SetKeyDelay" to create global delays while using "Send", but that is global (not per event).

My original hotkey has an imagesearch that does one thing when an image is found and if the image is not found it is supposed to just passthrough the key combo (ctrl+7). I figured I should focus on the simple case of passing through a simple key combo before I make the hotkey more complicated. The original hotkey looks something like this (to sate your curiosity).

Code: Select all

^7::
ImageSearch,,, 480, 50, 560, 100, *1 *TransBlack img\test.png
if ErrorLevel = 0
{
	SendInput, {7 Down}
	Sleep, 25
	SendInput, {7 Up}
}
else
{
	SendInput, {Ctrl Down}
	Sleep, 25
	SendInput, {7 Down}
	Sleep, 25
	SendInput, {7 Up}
	Sleep, 25
	SendInput, {Ctrl Up}
}
Sleep, 35
Return
[Mod edit: quote tags to [code][/code] tags.]
User avatar
mikeyww
Posts: 26885
Joined: 09 Sep 2014, 18:38

Re: Weird Modifier Behavior

18 Jun 2021, 08:58

Code: Select all

$^7::
SetKeyDelay, 25, 25
ImageSearch,,, 480, 50, 560, 100, *1 *TransBlack img\test.png
Send % ErrorLevel ? "^7" : "7"
Return
If you prefer your script, then precede the hotkey with $ as shown here and also earlier in this thread.
skylr616
Posts: 9
Joined: 06 Nov 2017, 14:53

Re: Weird Modifier Behavior

18 Jun 2021, 10:52

Adding "$" doesn't fix the problem when I use multiple sends (with custom sleeps between). The following code doesn't work (it just sends "7"). I'm not sure what you mean by "...and also earlier in this thread" so that may be what I'm missing.

Code: Select all

$^7::
SendInput, {Ctrl Down}
Sleep, 78
SendInput, {7 Down}
Sleep, 25
SendInput, {7 Up}
Sleep, 37
SendInput, {Ctrl Up}
Return
I'm simplifying my question a bit (and my ugly code) to try to isolate the issue. I can make the script work if I do it all in a single send with durations set by SetKeyDelay (as I mentioned previously)... but my goal is to have fine-grain control over the press duration and the time between presses for each key within each hotkey. This seems to necessitate separate Sends. If this is just not possible (in a relatively simple way), I understand. That is what I'm trying to find out.
User avatar
mikeyww
Posts: 26885
Joined: 09 Sep 2014, 18:38

Re: Weird Modifier Behavior  Topic is solved

18 Jun 2021, 14:40

The following worked in my test. Note that sleep, in general, is not precise.

Code: Select all

$^7::
KeyWait, 7
KeyWait, Ctrl
SoundBeep, 1500
SendInput {Ctrl Down}
Sleep, 78
SendInput {7 Down}
Sleep, 25
SendInput {7 Up}
Sleep, 37
SendInput {Ctrl Up}
SoundBeep, 1000
Return
Trigger this in Notepad. You can then check the KeyHistory.
skylr616
Posts: 9
Joined: 06 Nov 2017, 14:53

Re: Weird Modifier Behavior

18 Jun 2021, 15:25

You are my hero. I was just trying to figure out how to get it to activate on release of the hotkey and this is exactly what this does!

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Joey5, RandomBoy and 387 guests