AutoHotInterception (AHI): Multi-Keyboard / Multi-Mouse support for AHK. Per-device blocking!

Post your working scripts, libraries and tools
sharply-overcrowd
Posts: 3
Joined: 07 Oct 2019, 02:15

Re: AutoHotInterception (AHI): Multi-Keyboard / Multi-Mouse support for AHK. Per-device blocking!

07 Oct 2019, 02:48

evilC wrote:
03 Jan 2019, 17:25
I think something like #if cm1.IsActive && WinActive("blah") may work
Hi,
What is the proper way to use AHI with several Winactive conditions?
I use several #If cm1.IsActive && WinActive("ahk_exe xxxx.exe"), for different apps but sometimes the hotkey is not sent.
Autohokey catches the key each time, but cm1.IsActive doesn't seem to be active so it just sends the regular key.
It's hard to reproduce because it's a bit random, but the more i add #If cm1.IsActive && WinActive("ahk_exe xxxx.exe") conditions, the more often it happens.

Here is a test code: (I am new at AHK, so I am probably not doing things right):

Code: Select all

#include Lib\AutoHotInterception.ahk
AHI := new AutoHotInterception()
id1 := AHI.GetKeyboardId(0x0C45, 0x7811, 1)
cm1 := AHI.CreateContextManager(id1)
return 

#If cm1.IsActive && WinActive("ahk_exe apptest.exe")
Numpad0::msgbox test
#If
#If cm1.IsActive && WinActive("ahk_exe apptest1.exe")
Numpad0::msgbox test
#If
#If cm1.IsActive && WinActive("ahk_exe apptest2.exe")
Numpad0::msgbox test
#If
#If cm1.IsActive && WinActive("ahk_exe apptest3.exe")
Numpad0::msgbox test
#If
#If cm1.IsActive && WinActive("ahk_exe apptest4.exe")
Numpad0::msgbox test
#If
#If cm1.IsActive && WinActive("ahk_exe apptest5.exe")
Numpad0::msgbox test
#If
#If cm1.IsActive && WinActive("ahk_exe apptest6.exe")
Numpad0::msgbox test
#If
#If cm1.IsActive && WinActive("ahk_exe apptest7.exe")
Numpad0::msgbox test
#If
#If cm1.IsActive && WinActive("ahk_exe apptest8.exe")
Numpad0::msgbox test
#If
#If cm1.IsActive && WinActive("ahk_exe apptest9.exe")
Numpad0::msgbox test
#If
#If cm1.IsActive && WinActive("ahk_exe apptest0.exe")
Numpad0::msgbox test
#If
#If cm1.IsActive
Numpad0::msgbox test
#If
And a AHK log when the hotkey is not sent:

Code: Select all

213: Sleep,0
214: this.IsActive := state  
215: }
---- C:\Users\Alex\Google Drive\Apps\AutoHotInterception\keypad_work.ahk
012: if cm1.IsActive && WinActive("ahk_exe apptest.exe")  
016: if cm1.IsActive && WinActive("ahk_exe apptest1.exe")  
020: if cm1.IsActive && WinActive("ahk_exe apptest2.exe")  
---- C:\Users\Alex\Google Drive\Apps\AutoHotInterception\Lib\AutoHotInterception.ahk
213: Sleep,0
---- C:\Users\Alex\Google Drive\Apps\AutoHotInterception\keypad_work.ahk
024: if cm1.IsActive && WinActive("ahk_exe apptest3.exe")  
---- C:\Users\Alex\Google Drive\Apps\AutoHotInterception\Lib\AutoHotInterception.ahk
214: this.IsActive := state  
215: }
---- C:\Users\Alex\Google Drive\Apps\AutoHotInterception\keypad_work.ahk
028: if cm1.IsActive && WinActive("ahk_exe apptest4.exe")  
032: if cm1.IsActive && WinActive("ahk_exe apptest5.exe")  
036: if cm1.IsActive && WinActive("ahk_exe apptest6.exe")  
040: if cm1.IsActive && WinActive("ahk_exe apptest7.exe")  
044: if cm1.IsActive && WinActive("ahk_exe apptest8.exe")  
048: if cm1.IsActive && WinActive("ahk_exe apptest9.exe")  
052: if cm1.IsActive && WinActive("ahk_exe apptest0.exe")  
057: if cm1.IsActive   (0.08)
---- C:\Users\Alex\Google Drive\Apps\AutoHotInterception\Lib\AutoHotInterception.ahk
213: Sleep,0
214: this.IsActive := state
Thanks
User avatar
evilC
Posts: 4740
Joined: 27 Feb 2014, 12:30

Re: AutoHotInterception (AHI): Multi-Keyboard / Multi-Mouse support for AHK. Per-device blocking!

07 Oct 2019, 08:56

This is a known issue, adding more conditions to a #If statement increases the delay, and I *think* #if statements have a certain amount of time to resolve true or false before AHK just assumes false.
What you could try is to set a global variable to indicate which app is active, as that may resolve quicker (ie have a SetTimer checking active app and setting a variable accordingly)
If this does not work, then you could almost certainly fix it using Subscription Mode in AHI rather than Context Mode
I could maybe solve this by having AHI check for input more often - at the moment it does so once every ~15ms (The quickest I can do so with normal sleeps) - I do have some code to do this on a 1ms timer using MultiMedia timers, I could maybe port it into AHI and see if that solves your issue
sharply-overcrowd
Posts: 3
Joined: 07 Oct 2019, 02:15

Re: AutoHotInterception (AHI): Multi-Keyboard / Multi-Mouse support for AHK. Per-device blocking!

07 Oct 2019, 23:09

Thanks. I will have a look at subscription mode.
Is it possible to detect a 2 key-combination with it ?
MikuGeniu
Posts: 2
Joined: 12 Oct 2019, 21:07

Re: AutoHotInterception (AHI): Multi-Keyboard / Multi-Mouse support for AHK. Per-device blocking!

12 Oct 2019, 21:19

evilC wrote:
08 Oct 2019, 09:23
No, you would need to manually handle that yourself
Hello,Can AHI work like Taran's this vedio?
https://www.youtube.com/watch?v=y3e_ri-vOIo&list=PL2DzFnV-Dr4YaZE2jIJNWsi_wEZCoFFqF&index=4&t=0s
User avatar
evilC
Posts: 4740
Joined: 27 Feb 2014, 12:30

Re: AutoHotInterception (AHI): Multi-Keyboard / Multi-Mouse support for AHK. Per-device blocking!

13 Oct 2019, 12:31

v0.4.10 has been released!
Devices now poll at 1ms instead of ~15ms
This now means that if you are using a mouse set to 1000hz updates, AHK will be notified of mouse movement much more rapidly.
However, this may result in very high CPU load as AHK is not very suitable for this high a rate of input

@sharply-overcrowd Can you test if this makes Context Mode work better for you?
sharply-overcrowd
Posts: 3
Joined: 07 Oct 2019, 02:15

Re: AutoHotInterception (AHI): Multi-Keyboard / Multi-Mouse support for AHK. Per-device blocking!

14 Nov 2019, 02:16

evilC wrote:
13 Oct 2019, 12:31
@sharply-overcrowd Can you test if this makes Context Mode work better for you?
I haven't tested AHI a lot recently. I am using intercept.exe now and it works okay for my use.
But with the example code I posted, this release doesn't seem to improve much.

Return to “Scripts and Functions”

Who is online

Users browsing this forum: elModo7 and 51 guests