Ctrl hotkey

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
akirofe
Posts: 149
Joined: 05 Apr 2021, 21:54

Ctrl hotkey

13 Jun 2021, 20:28

Hi guys!

Please kindly help me with the problems I'm having:

I have the code below:

Code: Select all

a & s::
send {WheelDown}{WheelDown}{WheelDown}{WheelDown}{WheelDown}{WheelDown}{WheelDown}{WheelDown}{WheelDown}
return
Problem 1:
I would like to press Ctrl+a+s for the equivalent of Ctrl+WheelDown , but it doesn't seem to work.

Problem 2:
Without AHK on, when we type "a" and "s" fast, as in the word "pleASe", usually the "s" goes down while the "a" is still down, but somehow it still works and type "as" for us.
So, could you please show me if there is a "delay" threshold code to apply, so that "a & s" only hotkey to WheelDown when I hold "a" long enough pass the threshold, otherwise if "s" was down right after a, it'll type "as" as normal.

That would help me hugely!!!!

Thank you very much guys!!!!
User avatar
mikeyww
Posts: 26856
Joined: 09 Sep 2014, 18:38

Re: Ctrl hotkey

13 Jun 2021, 21:48

Although you can use GetKeyState() to assess whether Ctrl is pressed, AHK does not handle that sort of three-key situation consistently. KeyWait can be used to determine whether keys are held for a certain amount of time.
akirofe
Posts: 149
Joined: 05 Apr 2021, 21:54

Re: Ctrl hotkey

14 Jun 2021, 01:42

mikeyww wrote:
13 Jun 2021, 21:48
Although you can use GetKeyState() to assess whether Ctrl is pressed, AHK does not handle that sort of three-key situation consistently. KeyWait can be used to determine whether keys are held for a certain amount of time.
I tried and read your link but it seems beyond my capability to understand easily... Could you please help me to fix my code by what you meant please? Thank you very much!!
*** Thank you for reading. I am not in coding and know almost nothing about professional coding, hope for your patience and deeply appreciate any of your kind helps. My current interest in this awesome AHK is due to that my work is graphical ((architect/CAD) and, to reduce strains, my right hand is better off not leaving the mouse (an MMO mouse that has 12 side keys which I maps a lot of F keys and other keys in) as much as possible. All the best you lovely coders! ***
User avatar
mikeyww
Posts: 26856
Joined: 09 Sep 2014, 18:38

Re: Ctrl hotkey

14 Jun 2021, 06:41

I do not know the solution, because as I mentioned, AHK does not handle three keys consistently. Below is a general idea but with inconsistency. This script is not ideal. I added some code as a workaround to some of the problems with consistency. Others might have better solutions, but I don't think that you will be able to use the three keys together consistently. If you look at the KeyHistory, you will see what is happening and perhaps also why the script does not always work.

Code: Select all

#InstallKeybdHook

#If GetKeyState("Ctrl", "P") & on
s::
^s::Return

#If GetKeyState("Ctrl", "P")
a & s::
If on
 Return
on := True
KeyWait, a, T.3
If ErrorLevel {
 While GetKeyState("a", "P") & GetKeyState("s", "P") {
  SendInput {Ctrl up}{WheelDown}
  Sleep, 25
 }
} Else SendInput as
KeyWait, a
KeyWait, s
KeyWait, Ctrl
SendInput {a up}{s up}{Ctrl up}
on := False
Return
#If
akirofe
Posts: 149
Joined: 05 Apr 2021, 21:54

Re: Ctrl hotkey

15 Jun 2021, 00:18

Thank you very much Mikeyww!!
*** Thank you for reading. I am not in coding and know almost nothing about professional coding, hope for your patience and deeply appreciate any of your kind helps. My current interest in this awesome AHK is due to that my work is graphical ((architect/CAD) and, to reduce strains, my right hand is better off not leaving the mouse (an MMO mouse that has 12 side keys which I maps a lot of F keys and other keys in) as much as possible. All the best you lovely coders! ***
akirofe
Posts: 149
Joined: 05 Apr 2021, 21:54

Re: Ctrl hotkey

16 Jun 2021, 05:15

mikeyww wrote:
14 Jun 2021, 06:41
I do not know the solution, because as I mentioned, AHK does not handle three keys consistently. Below is a general idea but with inconsistency. This script is not ideal. I added some code as a workaround to some of the problems with consistency. Others might have better solutions, but I don't think that you will be able to use the three keys together consistently. If you look at the KeyHistory, you will see what is happening and perhaps also why the script does not always work.

Code: Select all

#InstallKeybdHook

#If GetKeyState("Ctrl", "P") & on
s::
^s::Return

#If GetKeyState("Ctrl", "P")
a & s::
If on
 Return
on := True
KeyWait, a, T.3
If ErrorLevel {
 While GetKeyState("a", "P") & GetKeyState("s", "P") {
  SendInput {Ctrl up}{WheelDown}
  Sleep, 25
 }
} Else SendInput as
KeyWait, a
KeyWait, s
KeyWait, Ctrl
SendInput {a up}{s up}{Ctrl up}
on := False
Return
#If
Hi mikeyww,

Could you please also help me with Problem 2 as mentioned above:

Problem 2:
Without AHK on, when we type "a" and "s" fast, as in the word "pleASe", usually the "s" goes down while the "a" is still down, but somehow it still works and type "as" for us.
So, could you please show me if there is a "delay" threshold code to apply, so that "a & s" only hotkey to WheelDown when I hold "a" long enough pass the threshold, otherwise if "s" was down right after a, it'll type "as" as normal.

Thank you very much Mikeyww!!
*** Thank you for reading. I am not in coding and know almost nothing about professional coding, hope for your patience and deeply appreciate any of your kind helps. My current interest in this awesome AHK is due to that my work is graphical ((architect/CAD) and, to reduce strains, my right hand is better off not leaving the mouse (an MMO mouse that has 12 side keys which I maps a lot of F keys and other keys in) as much as possible. All the best you lovely coders! ***
User avatar
mikeyww
Posts: 26856
Joined: 09 Sep 2014, 18:38

Re: Ctrl hotkey

16 Jun 2021, 06:43

The KeyWait as shown is the way to determine whether a key is held for a specified amount of time. I think you have another newer post about this same issue? Try Rohwedder's scripts!

https://www.autohotkey.com/boards/viewtopic.php?f=76&t=91657&p=405228#p405228

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Chunjee, ShatterCoder and 128 guests