What must be done to use multiple hotkeys simultaneously? Topic is solved

Ask for help, how to use AHK_H, etc.
asdsk9skdsdas
Posts: 36
Joined: 10 Mar 2019, 21:52

What must be done to use multiple hotkeys simultaneously?

Post by asdsk9skdsdas » 06 Jan 2021, 21:36

I am using AHK_H V1 because I want to be able to trigger multiple hotkeys simultaneously. I have installed it by copying all the files from the x64w folder to C:\Program Files\AutoHotkey. Say I am running the script below (just an example), how would I trigger 1 and 2 simultaneously?

Code: Select all

1::send a
2::send b
HotKeyIt
Posts: 2364
Joined: 29 Sep 2013, 18:35
Contact:

Re: What must be done to use multiple hotkeys simultaneously?

Post by HotKeyIt » 06 Jan 2021, 22:38

You will have to run in separate threads:

Code: Select all

thread1:=AhkThread("1::send a")
2::send b
asdsk9skdsdas
Posts: 36
Joined: 10 Mar 2019, 21:52

Re: What must be done to use multiple hotkeys simultaneously?

Post by asdsk9skdsdas » 06 Jan 2021, 23:06

HotKeyIt wrote:
06 Jan 2021, 22:38
You will have to run in separate threads:

Code: Select all

thread1:=AhkThread("1::send a")
2::send b
It seems I am only able to trigger 1 and 2 simultaneously if I press them both at the exact same time. This is fairly hard to achieve because pressing one of them just slightly earlier will result in only 1 hotkey triggering. Is this something that can be addressed without combining 1 and 2 with &?

I just started using AHK_H but is multithreading with AHK_H basically just like AHK_L running another script with the code written in AhkThread?
HotKeyIt
Posts: 2364
Joined: 29 Sep 2013, 18:35
Contact:

Re: What must be done to use multiple hotkeys simultaneously?

Post by HotKeyIt » 07 Jan 2021, 01:25

Yes, it is similar to running 2 scripts.
I just tested and it works fine for me, even if I press the second hotkey later.
asdsk9skdsdas
Posts: 36
Joined: 10 Mar 2019, 21:52

Re: What must be done to use multiple hotkeys simultaneously?

Post by asdsk9skdsdas » 07 Jan 2021, 03:03

HotKeyIt wrote:
07 Jan 2021, 01:25
Yes, it is similar to running 2 scripts.
I just tested and it works fine for me, even if I press the second hotkey later.
I think my problem is with how Windows sends key presses rather than with AHK or multithreading. If you press 1 then 2 not simultaneously and hold both keys, Windows will send this

122222222222222222222222222222222222

Since 1 is not being sent, my hotkey for 1 does not trigger in AHK. This phenomenon is described here https://superuser.com/questions/1597657/what-is-the-expected-behavior-when-holding-down-two-keys-on-a-keyboard.
HotKeyIt
Posts: 2364
Joined: 29 Sep 2013, 18:35
Contact:

Re: What must be done to use multiple hotkeys simultaneously?

Post by HotKeyIt » 07 Jan 2021, 07:56

If you need that, you can do it like this:

Code: Select all

thread1:=AhkThread("
(
#MaxThreadsPerHotkey 1
1::
	While GetKeyState(""1"",""P"")
		send a
Return
)")
#MaxThreadsPerHotkey 1
2::
	While GetKeyState("2","P")
		send b
Return
asdsk9skdsdas
Posts: 36
Joined: 10 Mar 2019, 21:52

Re: What must be done to use multiple hotkeys simultaneously?

Post by asdsk9skdsdas » 07 Jan 2021, 21:13

HotKeyIt wrote:
07 Jan 2021, 07:56
If you need that, you can do it like this:

Code: Select all

thread1:=AhkThread("
(
#MaxThreadsPerHotkey 1
1::
	While GetKeyState(""1"",""P"")
		send a
Return
)")
#MaxThreadsPerHotkey 1
2::
	While GetKeyState("2","P")
		send b
Return
Do you know why in the case below holding 1 and 2 simultaneously results in zigzag movement rather than smooth diagonal movement?

Code: Select all

thread1:=AhkThread("
(
#MaxThreadsPerHotkey 1
CoordMode, Mouse, Screen
SendMode Input
1::
	While GetKeyState(""1"",""P"")
		MouseMove, 10,0,, R
Return
)")

#MaxThreadsPerHotkey 1
CoordMode, Mouse, Screen
SendMode Input
2::
	While GetKeyState("2","P")
		MouseMove, 0,10,, R
Return
HotKeyIt
Posts: 2364
Joined: 29 Sep 2013, 18:35
Contact:

Re: What must be done to use multiple hotkeys simultaneously?  Topic is solved

Post by HotKeyIt » 07 Jan 2021, 22:01

That is what you defined, move 10 pixels right or down, it cannot be executed simultaneously, I assume windows ignores one of the mousemove.
Post Reply

Return to “Ask for Help”