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

Post your working scripts, libraries and tools.
User avatar
evilC
Posts: 4822
Joined: 27 Feb 2014, 12:30

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

Post by evilC » 21 Mar 2023, 14:52

Now compatible with AHK v2!
Old AHK v1 thread

What can it do for me?
AHI allows you to react to keyboard and mouse events in much the same way as AHK does, only with multiple keyboards and/or mice.

It can work in two modes (Both work at the same time)
Context mode is the simplest - you wrap your normal hotkeys in an #if statement, and AHI turns them on when the specific keyboard you wish to react to is about to send an event, and off again afterwards.

Subscription mode is an alternative to AHK's normal hotkey system - you can get notification of the state of single keys (No multi-key bindings, you would have to handle that yourself), buttons etc, whilst optionally completely blocking Windows from seeing the event.
In Subscription mode, you can also subscribe to "Raw" mouse movement, as you would get from RawInput. Both "Relative" (Regular mouse) and "Aboslute" (Graphics Tablet / LightGun) mouse modes are supported.

In addition to both of the input modes, you can send input (button presses, mouse movement etc) from a specific device.

How does it work?
AHI is a wrapper for Francisco Lopez' Interception driver.
It is written in C# (All source is available on the GitHub page) and is packaged as a DLL
You load this DLL using Lexikos' CLR linrary, and it loads the main Interception DLL and handles interaction with it for you.
A handy AHK wrapper is provided to allow you to easily load the DLL.
All files except the Interception DLL are included, you just need to install the Interception driver and copy it's DLL into the folder you downloaded AHI into.

READ THE INSTRUCTIONS AND WARNINGS IN THE DOCUMENTATION!!

GitHub page (Documentation etc)

Download from here

hpta
Posts: 24
Joined: 27 Sep 2019, 01:43

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

Post by hpta » 06 Apr 2023, 07:17

According to README.md I installed Intereception driver and extracted the "AHK v2" folder from .zip file on https://github.com/evilC/AutoHotInterception/releases/tag/v0.9.0

When I try to run Monitor.ahk it shows this:
image.png
image.png (20.78 KiB) Viewed 2995 times
Please could take a look at this?

Adventurer
Posts: 23
Joined: 18 Apr 2019, 06:24

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

Post by Adventurer » 22 Apr 2023, 06:01

hpta wrote:
06 Apr 2023, 07:17
According to README.md I installed Intereception driver and extracted the "AHK v2" folder from .zip file on https://github.com/evilC/AutoHotInterception/releases/tag/v0.9.0

When I try to run Monitor.ahk it shows this:
image.png
Please could take a look at this?
Move the dll into the Lib folder, it seems the release put it in the wrong place for some reason.

LAPIII
Posts: 667
Joined: 01 Aug 2021, 06:01

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

Post by LAPIII » 22 Apr 2023, 09:19

@Adventurer I did exactly that and when I ran test.ahk I got:
test.ahk 22_04_23 10⦂14⦂52⦂533 AM.jpg
test.ahk 22_04_23 10⦂14⦂52⦂533 AM.jpg (46.25 KiB) Viewed 2809 times
Also, Where do you get the interception driver?
EDIT: if it is https://github.com/oblitum/Interception/releases then I need help. I put the extracted zip on my desktop and from an elevated terminal I ran cd C:\Users\LPIII\OneDrive\Desktop\AHK\Interception\Interception\command line installer then install-interception.exe /install. It then said Could not write to \system32\drivers.

Adventurer
Posts: 23
Joined: 18 Apr 2019, 06:24

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

Post by Adventurer » 26 Apr 2023, 20:24

LAPIII wrote:
22 Apr 2023, 09:19
@Adventurer I did exactly that and when I ran test.ahk I got:

test.ahk 22_04_23 10⦂14⦂52⦂533 AM.jpg

Also, Where do you get the interception driver?
EDIT: if it is https://github.com/oblitum/Interception/releases then I need help. I put the extracted zip on my desktop and from an elevated terminal I ran cd C:\Users\LPIII\OneDrive\Desktop\AHK\Interception\Interception\command line installer then install-interception.exe /install. It then said Could not write to \system32\drivers.
You're on the right track, but if it's throwing you that error, you probably aren't actually on an elevated terminal. Try right clicking Start Menu, start Windows PowerShell (Admin) or Command Prompt (Admin), then run those commands again. (Except, if you're on PowerShell, you'll need to do .\install-interception.exe /install instead.)

LAPIII
Posts: 667
Joined: 01 Aug 2021, 06:01

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

Post by LAPIII » 26 Apr 2023, 20:58

Administrator_Command_Prompt 26_04_23 09⦂57⦂39⦂964 PM.jpg
Administrator_Command_Prompt 26_04_23 09⦂57⦂39⦂964 PM.jpg (74.73 KiB) Viewed 2711 times

Adventurer
Posts: 23
Joined: 18 Apr 2019, 06:24

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

Post by Adventurer » 26 Apr 2023, 21:06

LAPIII wrote:
26 Apr 2023, 20:58
Administrator_Command_Prompt 26_04_23 09⦂57⦂39⦂964 PM.jpg
That's strange. Did you delete your "windir" environment variable, by chance?

Try setx windir C:\Windows /m from an admin terminal, close the terminal and reopen it to refresh the environment variables, and then try installing the interception driver again.

If that doesn't work, maybe you have your terminal set up in such a way that is removing all environment variables when launching. (I don't know how or why that would be the case, but I'm just covering all the bases here.) In which case, try running set "windir=C:\Windows" and then, without closing terminal, try the install-interception.exe /install command again.

LAPIII
Posts: 667
Joined: 01 Aug 2021, 06:01

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

Post by LAPIII » 26 Apr 2023, 21:15

I wouldn't know how to delete my WINDIR environment.
Administrator_Command_Prompt 26_04_23 10⦂13⦂13⦂483 PM.jpg
Administrator_Command_Prompt 26_04_23 10⦂13⦂13⦂483 PM.jpg (81.2 KiB) Viewed 2672 times

Adventurer
Posts: 23
Joined: 18 Apr 2019, 06:24

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

Post by Adventurer » 26 Apr 2023, 21:25

LAPIII wrote:
26 Apr 2023, 21:15
I wouldn't know how to delete my WINDIR environment.

Administrator_Command_Prompt 26_04_23 10⦂13⦂13⦂483 PM.jpg
As I said, you have to restart your terminal after the setx command.

If it's still not working, try typing set and make sure the windir variable is in the list it gives you, pointing to C:\Windows

LAPIII
Posts: 667
Joined: 01 Aug 2021, 06:01

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

Post by LAPIII » 02 May 2023, 15:30

I fixed the issue with a suggestion from someone on Github, which was to run install-interception.exe /uninstall instead of install-interception.exe /install. After a restart and then running the latter command, it installed successfully. :thumbup:
Last edited by LAPIII on 20 Jul 2023, 13:04, edited 1 time in total.

LAPIII
Posts: 667
Joined: 01 Aug 2021, 06:01

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

Post by LAPIII » 03 May 2023, 10:57

LAPIII wrote:
22 Apr 2023, 09:19
@Adventurer I did exactly that and when I ran test.ahk I got:

test.ahk 22_04_23 10⦂14⦂52⦂533 AM.jpg
OK, in AutoHotInteception\AHK v2 I moved AutoHotInterception.dll into the Lib folder there. So why do I get the error?

sr1thp0c
Posts: 25
Joined: 02 Mar 2023, 06:14

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

Post by sr1thp0c » 05 May 2023, 13:49

How do I make it silently fail in the background if the device is not plugged in? Right now it throws an error and exits the whole script. Wrapping it in a try statement doesn't seem to help either.

Also in my compiled executable, running it the first time works as it should but running it a second time shows a messagebox with just the word "Failed", I tried looking inside AutoHotInterception.ahk but couldn't find any string that corresponds to this error so I have no clue where this error is coming from. If I delete the generated Lib folder by the executable it works again until the next time I close and reopen the exe.

homies50
Posts: 15
Joined: 07 Feb 2019, 00:04

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

Post by homies50 » 15 Mar 2024, 17:38

Hi @evilC ! I am having a problem with remapping the mousewheel. It is working fine but the only problem is that it types the “w” or “s” while performing scroll at the same time. Please help.

Code: Select all

#Requires AutoHotkey v2.0-rc.2 64-bit
#SingleInstance force
Persistent
#include C:\Users\Sunny\Documents\Hotkey\AutoHotkeyInterception\Lib\AutoHotInterception.ahk
#MaxThreadsPerHotkey 1

AHI := AutoHotInterception()
zelotesc18Id := AHI.GetKeyboardId(0x12C9, 0x2003)
cm1 := AHI.CreateContextManager(zelotesc18Id)

#HotIf cm1.IsActive
*w::
{
    while GetKeyState("w", "P"){
        Sleep 50
        SendInput "{WheelUp}"
        Sleep 50
        break         
    }
}

*s::
{
    while GetKeyState("s", "P"){
        Sleep 50
        SendInput "{WheelDown}"
        Sleep 50
        break         
    }
}

#HotIf

Post Reply

Return to “Scripts and Functions (v2)”