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

Post your working scripts, libraries and tools for AHK v1.1 and older

sharply-overcrowd
Posts: 3
Joined: 07 Oct 2019, 02:15

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

Post by sharply-overcrowd » 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: 4822
Joined: 27 Feb 2014, 12:30

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

Post by evilC » 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!

Post by sharply-overcrowd » 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!

Post by MikuGeniu » 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: 4822
Joined: 27 Feb 2014, 12:30

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

Post by evilC » 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!

Post by sharply-overcrowd » 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.

scriptors
Posts: 227
Joined: 25 Feb 2016, 09:01

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

Post by scriptors » 09 Dec 2019, 15:10

Sorry but I can't install and work with AutoHotInterception … strange but true :(

I use Autohotkey_H (on Win10 64) and if i try Monitor.ahk have this:

Code: Select all

---------------------------
AutoHotkey
---------------------------
Error: CONTINUABLE EXCEPTION_ACCESS_VIOLATION

Mouse and Keyboard hooks have been disabled.

  -  Press yes to exit thread and continue execution.
  -  Press no to continue thread (debug).
  -  Press cancel to exit application.

Exception was caused in thread id: 7844
Line: 144
LineFile: C:\Program Files\AutoHotkey\Lib\AutoHotInterception.ahk
---------------------------
Sì   No   Annulla   
---------------------------

jvachez
Posts: 3
Joined: 10 Dec 2019, 12:28

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

Post by jvachez » 14 Dec 2019, 12:50

Hello

I have successfully got my keyboards VID and PID. But I don't know how to detect which keyboard has send the keys. I need to know that because my goal is to change Windows keyboard layout into QWERTY if I use my QWERTY keyboard or into AZERTY layout if I use my AZERTY keyboard.

dsieburgh
Posts: 2
Joined: 14 Dec 2019, 01:42

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

Post by dsieburgh » 15 Dec 2019, 05:36

This is brilliant - thanks so much! I have very quickly and easily shifted my setup to using your cool piece of software (see macro keyboard image attached) which I was previously accomplishing via LuaMacros+AHK. But, this is much cleaner and more elegant.

I have run into one issue though - the Pause/Break Key. Using the Monitor AHK you provided, if I press Pause/Break it shows Numlock(1/0 states)+LControl(4/5 states) and when I only press Numlock I get Numlock Keyname (just 0/1 states).

I am using Subscription mode. Do you know of any way I can differentiate between these two keys?
Attachments
IMG_1444.jpg
IMG_1444.jpg (1.18 MiB) Viewed 6944 times
Monitor.png
Monitor.png (57.71 KiB) Viewed 6944 times

User avatar
evilC
Posts: 4822
Joined: 27 Feb 2014, 12:30

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

Post by evilC » 15 Dec 2019, 12:36

jvachez wrote:
14 Dec 2019, 12:50
Hello

I have successfully got my keyboards VID and PID. But I don't know how to detect which keyboard has send the keys. I need to know that because my goal is to change Windows keyboard layout into QWERTY if I use my QWERTY keyboard or into AZERTY layout if I use my AZERTY keyboard.
In AHI, you subscribe to a specific device, so inherently you know what device the input is coming from, because it's the one you subscribed to, so this comment makes absolutely no sense

User avatar
evilC
Posts: 4822
Joined: 27 Feb 2014, 12:30

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

Post by evilC » 15 Dec 2019, 12:40

dsieburgh wrote:
15 Dec 2019, 05:36
The Pause/Break Key. Using the Monitor AHK you provided, if I press Pause/Break it shows Numlock(1/0 states)+LControl(4/5 states) and when I only press Numlock I get Numlock Keyname (just 0/1 states).
Confirmed, this is a bug.
Raised issue: https://github.com/evilC/AutoHotInterception/issues/55


User avatar
evilC
Posts: 4822
Joined: 27 Feb 2014, 12:30

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

Post by evilC » 15 Dec 2019, 17:28

AHI v0.5.0 has been released!

Added SubscribeKeyboard and SubscribeMouseButtons to subscribe to all keys or buttons on a device
The old undocumented Monitor class has been removed, Monitor.ahk now uses the new SubscribeKeyboard / SubscribeMouseButtons functions
Added some development tools to help me track down and squash bugs with ScanCode differences between AHK and AHI

Code: Select all

### Added
- SubscribeKeyboard and SubscribeMouseButtons can now be used to subscribe to all keys / buttons on a device
- Added ScanCodeTester Development Tool to investigate differences in AHI / AHK ScanCodes
### Changed
- Monitor.ahk now uses SubscribeKeyboard and SubscribeMouseButtons

dsieburgh
Posts: 2
Joined: 14 Dec 2019, 01:42

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

Post by dsieburgh » 15 Dec 2019, 22:27

evilC wrote:
15 Dec 2019, 12:40
Confirmed, this is a bug.
Raised issue: https://github.com/evilC/AutoHotInterception/issues/55
Thanks!

BuggyB
Posts: 44
Joined: 25 Mar 2019, 17:59

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

Post by BuggyB » 18 Dec 2019, 07:00

Hello evilC,
I'm posting to thank you, this is a great tool !

I had Bluetooth controllers designed for iOS/android in my drawers, they send things like arrow keys under windows and were therefore not useful. Now, I can take something like satechi st-arcm and do whatever I want with it.


One thing is strange with that particular BT controller though : one key (the bottom right one on the picture) is meant to go" home" on Android, and opens the default browser on Windows, but it is not intercepted. Not a big problem for me, but I was wondering how it can be, out of curiosity.

BuggyB
Posts: 44
Joined: 25 Mar 2019, 17:59

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

Post by BuggyB » 29 Dec 2019, 08:35

I can run my script, it is based on Subscription Example.ahk and works like w charm. But I would like to have a compiled version. When I run the compîled version I always get a msg :
"Unable to find lib\x64\interception.dll, exiting...
You should extract both x86 and x64 folders from the library folder in interception.zip into AHI's lib folder."

... but I have done that already and double-checked it.

I'm certainly missing something. Thank you


BuggyB
Posts: 44
Joined: 25 Mar 2019, 17:59

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

Post by BuggyB » 01 Jan 2020, 11:25

Hi evilC
evilC wrote:
30 Dec 2019, 04:03
I think it should work if you use this newer version of AutoHotInterception.ahk
Yes, it does work, a big thank you !

Post Reply

Return to “Scripts and Functions (v1)”