Repeating key combination issue

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
shawn9
Posts: 4
Joined: 05 Jul 2022, 10:29

Repeating key combination issue

Post by shawn9 » 05 Jul 2022, 10:36

I created a mapping like this:

Code: Select all

!j::Send {Down}
And when I press alt+j at the first time, it works well. But when I keep pressing these key combination without release, it sends j only.
I tried the following methods but failed:
1.

Code: Select all

*j::
If GetKeyState("alt") {
  Loop
  {
     Send {DOWN}
     sleep 500
     If !GetKeyState("j") {
       Break
     }
  }
}
Return
2.

Code: Select all

*j::
If GetKeyState("Control")
 Send {DOWN}
Else
 Send {Blind}x
Return
Any suggestion is welcome.
Thanks!
Last edited by BoBo on 05 Jul 2022, 11:14, edited 1 time in total.
Reason: Added [code][/code]-tags.

User avatar
mikeyww
Posts: 26885
Joined: 09 Sep 2014, 18:38

Re: Repeating key combination issue

Post by mikeyww » 05 Jul 2022, 11:44

Worked here. Test in Notepad, with no other code in the script, and no other scripts running.

shawn9
Posts: 4
Joined: 05 Jul 2022, 10:29

Re: Repeating key combination issue

Post by shawn9 » 05 Jul 2022, 23:05

Thanks for your confirmation.
I tested in Notepad on other three Windows10 laptops. And found different behavior on different laptop.
The version of AHK is 1.1.34.02.
The whole script is as follows:

!j::Send {Down}
!k::Send {Up}
!h::Send {Left}
!l::Send {Right}

The test scenario is:
Firstly, I input 100 lines with repeated content: 'aaaaaaaaaaaaaa' in Notepad.
Then I use alt+j/k/h/l to navigate, I will see letter j/k/h/l between letter a.
The point is the probability of occurrence is different, e.g. the one laptop is about 60%,
the other is about 5% more or less.
What is the cause of probability changing?
Is there any other stable solution for it? I means making probability zero.

By the way, I refered this links, but failed:
https://www.autohotkey.com/board/topic/61732-repeating-key-combo-problem/


Thanks!

BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: Repeating key combination issue

Post by BoBo » 05 Jul 2022, 23:09

Have you tried using a fixed priority setting? https://www.autohotkey.com/docs/commands/Process.htm#Priority

shawn9
Posts: 4
Joined: 05 Jul 2022, 10:29

Re: Repeating key combination issue

Post by shawn9 » 05 Jul 2022, 23:38

Thanks for your quick response!
I just tried to increase script priorty as follows:

Code: Select all

Process, priority, , High ; Make script own priorty high
!j::Send {Down}
return
!k::Send {Up}
return
!h::Send {Left}
return
!l::Send {Right}
return
But make no difference. The problem still exists.
Last edited by BoBo on 05 Jul 2022, 23:51, edited 1 time in total.
Reason: Added [code][/code]-tags.

User avatar
mikeyww
Posts: 26885
Joined: 09 Sep 2014, 18:38

Re: Repeating key combination issue

Post by mikeyww » 06 Jul 2022, 06:03

Perhaps:

Code: Select all

!j::SendInput {Down}
!k::SendInput {Up}
!h::SendInput {Left}
!l::SendInput {Right}

shawn9
Posts: 4
Joined: 05 Jul 2022, 10:29

Re: Repeating key combination issue

Post by shawn9 » 06 Jul 2022, 07:43

I made difference. After use SendInput instead of Send, the probability of unexpected behavior occurrence becomes lower(almost less than 3%)
And I think it is acceptable, although it is not perfect :-)

Thanks guys for your help!

Post Reply

Return to “Ask for Help (v1)”