Strange fallback if one more hotkey added

Get help with using AutoHotkey and its commands and hotkeys
sandric
Posts: 11
Joined: 24 Oct 2017, 18:32
Facebook: Anton Kyrychenko
Google: Anton Kyrychenko
GitHub: sandric

Strange fallback if one more hotkey added

26 Oct 2017, 12:30

I'm not sure what the problem really is, so I'll explain my scenario:

I have that piece in my AHK script:

Code: Select all

<^>^+n::
	send nnn
return

<^>^+e::
	send eee
return
So far those two shortkeys works as expected. Now if I add third one:

Code: Select all

<^>^+n::
	send nnn
return

<^>^+e::
	send eee
return

<^>^+s::
	send sss
return
Now all three shortcuts stops working. Does anyone knows what it can be? May it be there is some limit to shortcuts per pressed keys?.
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Strange fallback if one more hotkey added

26 Oct 2017, 23:32

All 3 in the same script worked for me. LCtrl + Shift + RCtrl + letter, that's pretty awkward to press!

Perhaps you have some interference with some other hotkeys that are also in the script.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
sandric
Posts: 11
Joined: 24 Oct 2017, 18:32
Facebook: Anton Kyrychenko
Google: Anton Kyrychenko
GitHub: sandric

Re: Strange fallback if one more hotkey added

27 Oct 2017, 06:35

Yes, for sure, there's much more scripting with those keys, but the script is pretty long already to ask people to try understand it). Ok, I'll try to minimize it as possible to see reproducible error. For now I can tell that when you add third <^>^+s:: chord all of <^>^+ chords falling back to >^+ chords that are also in script.
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Strange fallback if one more hotkey added

27 Oct 2017, 08:06

- Did you try the hotkeys in a separate script by themselves?
- If you do just the n and s hotkeys, does the s one stop the n one from working?
- If you do just the e and s hotkeys, does the s one stop the e one from working?
- Are there other hotkeys that end with s, that feature ctrl or shift? You could search for lines that contains 's::'.
- If you put the s hotkey at the top of the script, does the s hotkey work?

Note: for a handy list of hotkeys used by the script, go to the main window and select: View, Hotkeys and their methods.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
sandric
Posts: 11
Joined: 24 Oct 2017, 18:32
Facebook: Anton Kyrychenko
Google: Anton Kyrychenko
GitHub: sandric

Re: Strange fallback if one more hotkey added

02 Nov 2017, 15:43

Ok, I tried to investigate the issue with debugger and have no idea at all whats going on. So here's my test script:

Code: Select all

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.


<^>^n::
	Send N
return

<^>^i::
	Send I
return

<^>^u::
	Send U
return

<^>^e::
	Send E
return



<^n::
	Send ln
return

<^i::
	Send li
return

<^u::
	Send lu
return

<^e::
	Send le
return



>^n::
	Send rn
return

>^i::
	Send ri
return

>^u::
	Send ru
return

>^e::
	Send re
return
Thats all. If with either one of n,i,u,e button pressed left control. it prints l+button, if right-control instead of left - r+button. If both left AND right control pressed with button - letter in upper case.

Now test results:

holding left control + each button gives: lnlilule - all right.
holding right control + each button gives: rnrirure - all right.
holding both right and left control + each button gives: rnIUre - working as expected for i and u, but falling back to only right control for n and e.

Here is output of key logger for leftctrl+rightctrl+i (working as expected)

Code: Select all

74  03F	 	u	0.08	F5             	
A3  11D	 	d	3.98	RControl       	
A2  01D	 	d	0.06	LControl       	
49  017	h	d	0.17	i              	
A2  01D	i	u	0.00	LControl       	
A3  11D	i	u	0.00	RControl       	
A0  02A	i	d	0.00	LShift         	
49  017	i	d	0.00	i              	
49  017	i	u	0.00	i              	
A0  02A	i	u	0.00	LShift         	
A2  01D	i	d	0.00	LControl       	
A3  11D	i	d	0.00	RControl       	
49  017	s	u	0.14	i              	
A3  11D	 	u	0.03	RControl       	
A2  01D	 	u	0.01	LControl       	
74  03F	 	d	0.58	F5
Here is output of key logger for leftctrl+rightctrl+n (faling back to only right ctrl)

Code: Select all

74  03F	 	u	0.11	F5             	
A3  11D	 	d	2.21	RControl       	
A2  01D	 	d	0.09	LControl       	
4E  031	h	d	0.05	n              	
A2  01D	i	u	0.00	LControl       	
A3  11D	i	u	0.00	RControl       	
52  013	i	d	0.00	r              	
52  013	i	u	0.00	r              	
4E  031	i	d	0.00	n              	
4E  031	i	u	0.00	n              	
A2  01D	i	d	0.00	LControl       	
A3  11D	i	d	0.00	RControl       	
4E  031	s	u	0.11	n              	
A2  01D	 	u	0.05	LControl       	
A3  11D	 	u	0.01	RControl       	
74  03F	 	d	0.59	F5
As you can see, in both examples, RControl and LControl is send from keyboard, but for some reason AHK chooses to fall back in one of them.

Now for the most fun stuff. Lets move both control pressed part of script from beginning of the script to the end:

Code: Select all

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.



<^n::
	Send ln
return

<^i::
	Send li
return

<^u::
	Send lu
return

<^e::
	Send le
return



>^n::
	Send rn
return

>^i::
	Send ri
return

>^u::
	Send ru
return

>^e::
	Send re
return



<^>^n::
	Send N
return

<^>^i::
	Send I
return

<^>^u::
	Send U
return

<^>^e::
	Send E
return
And try the same test:

holding left control + each button gives: lnlilule - all right.
holding right control + each button gives: rnrirure - all right.
holding both right and left control + each button gives: NElilu- working as expected for n and e, but falling back to only right control for i and u. IT FLIPS FALLBACK!!

Whats going on???
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Strange fallback if one more hotkey added

04 Nov 2017, 14:13

This is really interesting, and I'm not sure what the problem is. I wrote a script that allows every letter of the alphabet of to be checked, and to make it easier to change the order in which hotkeys are added, for testing purposes.

Perhaps this should be moved to Bug Reports, so it can get more attention.

One thing I do suspect is that certain keyboards cannot physically handle certain key combinations correctly.

Code: Select all

Loop, 26
{
	Hotkey, % "<^>^" Chr(96+A_Index), MyLabel
	Hotkey, % "<^" Chr(96+A_Index), MyLabel
	Hotkey, % ">^" Chr(96+A_Index), MyLabel
}
return

MyLabel:
vHotkey := A_ThisHotkey
vHotkey := StrReplace(vHotkey, "<^>^", "_") ;both LCtrl and RCtrl
vHotkey := StrReplace(vHotkey, "<^", "L") ;LCtrl
vHotkey := StrReplace(vHotkey, ">^", "R") ;RCrtl
SendInput, % vHotkey
;SoundBeep
return

;all 3 types of hotkey on
;output ;problem keys in uppercase
;_q_w_eRr_t_yRuRi_oRp ;qweRtyUIoP
;_a_sRd_fRg_h_jRk_l ;asDfGhjKl
;RbRn ;ZXCVBNM ;some keys weren't even received

;only the 'both' type of hotkey on
;output ;problem keys in uppercase
;_q_w_e_r_t_y_u_i_o_p ;qwertyuiop
;_a_s_d_f_g_h_j_k_l ;asdfghjkl
;_b_n ;ZXCVbnM ;some keys weren't received
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
sandric
Posts: 11
Joined: 24 Oct 2017, 18:32
Facebook: Anton Kyrychenko
Google: Anton Kyrychenko
GitHub: sandric

Re: Strange fallback if one more hotkey added

04 Nov 2017, 17:49

@jeeswg I know that, and I tested script with that in head. But as you can see - in logs all three buttons appears pushed down, and the appearance changes only after I move around shortkeys definitions. So I do think mb that a bug too. How should I move thread to Bug Reports, simply copy my last message into new thread?
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Strange fallback if one more hotkey added

04 Nov 2017, 18:17

All of the information in this thread is nicely complete, so either an admin/mod could move it to Bug Reports, or, we could just give this thread a bump every once in a while, in the Ask For Help forum.

There may be a workaround for this problem using #If and GetKeyState, i.e. even if we don't resolve the cause of this problem, it may be possible to get the functionality you desire. I will do some experiments.

One other interesting quirk with hotkeys that may or may not be related:
hotkeys can disable each other - AutoHotkey Community
https://autohotkey.com/boards/viewtopic ... 54#p167254
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Strange fallback if one more hotkey added

04 Nov 2017, 20:44

Here's an initial basic workaround:

Code: Select all

*<^n::
*<^i::
*<^u::
*<^e::
if GetKeyState("RCtrl", "P")
	SendInput, % "_" SubStr(A_ThisHotkey, StrLen(A_ThisHotkey))
else
	SendInput, % "L" SubStr(A_ThisHotkey, StrLen(A_ThisHotkey))
return

*>^n::
*>^i::
*>^u::
*>^e::
if GetKeyState("LCtrl", "P")
	SendInput, % "_" SubStr(A_ThisHotkey, StrLen(A_ThisHotkey))
else
	SendInput, % "R" SubStr(A_ThisHotkey, StrLen(A_ThisHotkey))
return
==================================================

Here's another attempt.

Code: Select all

#If GetKeyState("LCtrl", "P") && GetKeyState("RCtrl", "P")
*n::
*i::
*u::
*e::
SendInput, % "_" SubStr(A_ThisHotkey, StrLen(A_ThisHotkey))
return
#If

<^n::
<^i::
<^u::
<^e::
if GetKeyState("RCtrl", "P")
	SendInput, % "_" SubStr(A_ThisHotkey, StrLen(A_ThisHotkey))
else
	SendInput, % "L" SubStr(A_ThisHotkey, StrLen(A_ThisHotkey))
return

>^n::
>^i::
>^u::
>^e::
if GetKeyState("LCtrl", "P")
	SendInput, % "_" SubStr(A_ThisHotkey, StrLen(A_ThisHotkey))
else
	SendInput, % "R" SubStr(A_ThisHotkey, StrLen(A_ThisHotkey))
return
It's always possible to use Gosub in such circumstances, to separate the special hotkey handling and the code proper, thereby avoiding clutter.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA

Return to “Ask For Help”

Who is online

Users browsing this forum: Bing [Bot], Google [Bot], grosner and 47 guests