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
phasermaniac
Posts: 74
Joined: 09 Apr 2017, 14:05

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

10 Apr 2020, 15:06

Mmm, I updated but same problem.
I noticed that the Sourcecode.zip has the files updated to 10/4/2020, while AutoHotInterception.zip files seems older. So I updated AutoHotInterception.ahk, CLR.ahk and Unblocker.ps1 from Sourcecode.zip, is this right?

Many thanks anyway for your help!
tzink
Posts: 1
Joined: 11 Apr 2020, 17:09

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

11 Apr 2020, 17:23

I used this script without difficulty in the past. Thank you for this great work. However, after a reformat, I am having difficulty.

Specifically, I can't determine the VID/PID of my USB keyboard because of an error with Monitor.ahk

When I run Monitor.ahk and check any of the ID boxes, I get the following error:
Error in #include file
"C:\Users\asdf\OneDrive\Documents\AHK\Lib\AutoHotInterception.ahk":
0x80020006 - Unknown name.

Specifically: SubscribeKeyboard
...
Continue running the script?
Even if I press Yes continue, none of the IDs register any input from my keyboard.

Any advice?

Thanks!
ppapkor
Posts: 14
Joined: 30 Jan 2019, 03:22

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

17 Apr 2020, 01:04

hi im using this wonderful code over a year
Thanks a lot. you are my hero at all.

recently i'm stucking at "synthesize keep pressing key" problem.

For example if i press 'a' key on the notepad and keep pressing it,
the result will be 'a(little break)aaaaaaaaaaaaa'.

But when i synthesize key down with this code,
it ends with only single 'a'.

I know this could be done with multiple key down line but what I want to do is hold pressing down a key + move on to the next line.

keydown
(
running code area, while key is keep pressed(a aaaaaaaa...)
)
releasekey

Could it be possible?
nichatr
Posts: 7
Joined: 17 May 2019, 01:43
Contact:

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

21 Apr 2020, 12:46

Hello evilC, thank you for the great library!

I've encountered a problem: when I use the autohotkeyinterception in a separate script which I load at the start from my main context menu script, it seems that the second keyboard is not recognized.
So I put the <Context Example.ahk> code inside my main script. It works correctly when the two keyboards are connected, but when the second keyboard is not connected the following statement

Code: Select all

id2 := AHI2.GetKeyboardId(0x258A, 0x1006, 1)
causes an "ExitApp" so no script is loaded.

I've checked the source code and found the problem is in function GetDeviceId()

Code: Select all

	GetDeviceId(IsMouse, VID, PID, instance := 1) {
		static devType := {0: "Keyboard", 1: "Mouse"}
		dev := this.Instance.GetDeviceId(IsMouse, VID, PID, instance)
		if (dev == 0) {
			MsgBox % "Could not get " devType[isMouse] " with VID " VID ", PID " PID ", Instance " instance
			ExitApp
		}
		return dev
	}
distante
Posts: 1
Joined: 31 May 2020, 07:47

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

31 May 2020, 07:55

Hi, this is my first post so please bare with me.

I have a mouse that I move between 2 devices. An I am wondering which is the best way to not loose the current mapping when the id is missing (I mean besides restarting the script).

Thank you and thanks for this wonderful tool!
jthunderpants
Posts: 1
Joined: 25 Aug 2020, 18:09

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

25 Aug 2020, 18:20

Hi, I first want to thank you for this work, it's awesome. I've got a second keyboard working with a few subscriptions. I'm new to this format and haven't had much luck with context hotkeys.

Is there a good source of examples for autohotinterception scripts? If not I'd appreciate some help to get me started:

My goal is to have my second keyboard be used for latex shortcuts. Eg. "a" -> "\alpha". I have that working already. How can I make it so that shift + "a" -> "\Alpha"? Right now shift + "a" -> "|ALPHA".

Another trickier question is, can I move my 'I-beam' cursor is located? E.g. If I had a hotkey that output "\frac{}{}", I'd want the cursor between the first braces pair. I haven't seen any examples like this.

Any tips / insight appreciated, thanks!
Zoxver
Posts: 1
Joined: 18 Dec 2020, 08:34

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

18 Dec 2020, 08:43

Guys, hello. I was looking for how to make my AHK work in the game Cyberpunk 2077. I need the keyboard buttons to be pressed in the game. Everything works in the notebook, but not in the game itself. I searched and came across you. Could you help me. Thanks in advance.
P.S. I don't speak English very well.
unicorn79
Posts: 1
Joined: 12 Jan 2021, 00:43

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

12 Jan 2021, 01:08

Hi there!

Can you help me, please, is it possible with AutoHotInterception programmatically detect (intercept, capture) which win api (for example - mouse_event) directly requests the application I specified or even intercept global api calls to windows user32.dll, which holds mouse_event...
That is, something similar to the API MONITOR.
I tired to install global hooks as shown down will not help me, since they capture the already accomplished fact of api execution, but i need to capture only the api call procedure fact before it is actually executed. (code only for example in autohotkey to understand what i mean)...
`

Code: Select all

        hHookKeybd := DllCall("SetWindowsHookEx"
          , Int, WH_KEYBOARD_LL := 13
          , UInt, RegisterCallback("LowLevelKeyboardProc", "Fast")
          , UInt, DllCall("GetModuleHandle", UInt, 0)
          , UInt, 0)
     
       hHookMouse := DllCall("SetWindowsHookEx"
          , Int, WH_MOUSE_LL := 14
          , UInt, RegisterCallback("LowLevelMouseProc", "Fast")
          , UInt, DllCall("GetModuleHandle", UInt, 0)
          , UInt, 0)
[Mod edit: [code][/code] tags added.]

`
I have read, that AutoHotInterception is able to capture events from real devices (keyboard and mouse), but I am interested in global capturing calls to the api as a whole (it can be a mousemove, 100, 100, 100 command from autohotkey or the movement of a real USB HID mouse) ...

I know for sure that this is possible by other programms, since the product Api Monitor v2 can do this, but there are no convenient tools for processing the information received. http://dl4.joxi.net/drive/2021/01/12/0013/2011/870363/63/f680aed021.jpg

Thanks for your suggestions!
User avatar
submeg
Posts: 326
Joined: 14 Apr 2017, 20:39
Contact:

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

30 Jan 2021, 20:33

hi @Zoxver,

Are you specifically asking about the multi-device script or just AHK for gaming in general?

If you want to learn about AHK for gaming, there's a spot for all gaming questions in the forums.
____________________________________
Check out my site, submeg.com
Connect with me on LinkedIn
Courses on AutoHotkey :ugeek:
myles007
Posts: 1
Joined: 12 Mar 2021, 13:29

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

12 Mar 2021, 13:47

Hi

Firstly, I would like to thank those involved in creating this amazing tool!

Secondly, I need some help...

I would like to completely block a set of keyboard and mice to a SPECIFIC application (game) whether the game window is IN FOCUS OR NOT.

All the information I've been able to gather:

Code: Select all

keyboardId := AHI.GetKeyboardIdFromHandle("ACPI\VEN_PNP&DEV_0303")
mouseId := AHI.GetMouseId(0x1532, 0x0088)

Application:
ahk_class PIGS_MainWnd
Hunter310
Posts: 6
Joined: 09 Apr 2021, 22:15

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

11 Apr 2021, 16:48

Disculpen una pregunta,

Soy nuevo en el uso de estos scripts,

Y me gustaria saber como instalar correctamente la herramienta AHI en windows 10 home porque ya intente de varias maneras y no puedo hacerlo:

https://github.com/evilC/AutoHotInterception

Ademas si alguien me pudiera dar un ejemplo de como reconocer otro teclado y generar el código para este me seria de mucha ayuda.

Code: Select all

#If !GetKeyState("NumLock", "T")
NumpadDiv::Send, a
NumpadMult::Send, b
NumpadSub::Send, c
NumpadAdd::Send, d
NumpadEnter::Send, e
NumpadHome::Send, f
NumpadUp::Send, g
NumpadPgUp::Send, h
NumpadLeft::Send, i
NumpadClear::Send, j
NumpadRight::Send, k
NumpadEnd::Send, l
NumpadDown::Send, m
NumpadPgDn::Send, n
NumpadIns::Send, p
NumpadDel::Send, o

; NumLock , CapsLock, ScrollLock
Este codigo quiero aplicarlo a otro teclado diferente al que estoy usando

Gracias.
terribletom
Posts: 1
Joined: 04 May 2021, 11:42

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

04 May 2021, 12:21

If anyone is hitting Interception's 10 device limit the following solution might help (read below).
My hardware devices were installing virtual devices that were neither needed nor used.
Due to that some 'real' devices that I really needed were indexed above 10 and were not working.
For example my Logitech MX Anywhere Mouse and Brydge W-Touch Trackpad both were installing virtual keyboards in their HID containers.
(To see the list of sub devices by container go to Device Manager->View menu->Devices by Container).
Disabling those keyboard sub-devices the usual way was not possible, since 'Disable Device' button in Device Manager->Device X Properties->Driver tab was greyed out.
However I managed to disable those unneeded virtual devices and free up some Interception slots using the Group Policy solution described here :
https://www.ghacks.net/2017/06/03/stop-windows-from-installing-drivers-for-specific-devices/ [Mod edit: Link fixed.]
P.S. Thank you to AHI creators for this tool - it helped me a lot in improving my daily productivity and workflow.
xyupup
Posts: 3
Joined: 04 Dec 2016, 09:12

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

05 May 2021, 00:23

After executing UnsubscribeMouseButtons, it seems unable to subscribe again

Code: Select all

#SingleInstance force
#Persistent
#include Lib\AutoHotInterception.ahk

global AHI := new AutoHotInterception()

AHI.SubscribeMouseButtons(13,false, Func("test1"))
Sleep 3000
AHI.SubscribeMouseButtons(13,true, Func("test2"))


test1(code, state)
{
static isLocked := false
	if (state = 0)
	{
  isLocked := false
  return
	}
	if (isLocked)
  return
	isLocked := true
	
ToolTip % "Mouse Button - Code: " code ", State: " state	
AHI.UnsubscribeMouseButtons(13)					
}

test2(code, state)
{
ToolTip % "Mouse Button - Code: " code ", State: " state	
}
return
mavz
Posts: 7
Joined: 30 Jun 2021, 07:30

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

01 Jul 2021, 11:20

can you help me compile script, i have very little understanding in this
im trying to write scrip when hold ctrl and press A S or D for them to correspond with number pad action when using windows mouse keys
so when i hold ctrl and press A it will act as pressing ctrl and 4 on number pad ( in theory this should move cursor to the left )
when i hold ctrl and press S it will act as pressing ctrl and 5 on number pad ( in theory this should click the cursor )
so when i hold ctrl and press D it will act as pressing ctrl and 6 on number pad ( in theory this should move cursor to the right )
i tried doing this without AKI but fail, as it does not move cursor only inputs 4 5 6 in text boxes
these are my ID for A S D
Image
this is my 4 5 6 on number pad
Image

This is what i tried without AKI and it only inputs 4 5 6 in text box does not move cursor.

Code: Select all

^a::Send {Numpad4}
^s::Send {Numpad5}
^d::Send {Numpad6}
sorry for my bad English, i try my best to explain. i am in the discord (1MavZ) if you need quick answer
User avatar
evilC
Posts: 4822
Joined: 27 Feb 2014, 12:30

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

06 Jul 2021, 15:12

@mavz Windows mouse keys will probably not see keys sent by AHK's Send command, so probably won't work. Instead you should use AHI to send the keys

eg

Code: Select all

^a::AHI.SendKeyEvent(1, GetKeySC("Numpad4"), 1)
^a up::AHI.SendKeyEvent(1, GetKeySC("Numpad4"), 0)
But in general, this will be rubbish, as it won't work properly with diagonals

It's probably a lot simpler to just code your own equivalent of mouse keys
I have one here: https://github.com/evilC/TapHoldManager
See the KeyboardToMouse.ahk script (You will need to download the whole library, not just that one script)
Then change the keys to suit, eg
thm.Add("NumpadLeft", Func("HandleInput").Bind("x", "-1")) should be changed to thm.Add("^a", Func("HandleInput").Bind("x", "-1"))
Oh, and annoyingly, I left a tooltip command in on line 22, you can just comment that out
g0dArthas
Posts: 2
Joined: 12 Jul 2021, 00:52

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

12 Jul 2021, 01:02

Hello everyone,
first I want to begin by thanking everyone involved in this project.
Having said that I wanted to ask something. I've read about AutoHotInterception and I'm very impressed by it, but before installing and using it I want to be sure it does what I think is capable of. I've made an AHK script that uses DllCall and mouse_event and then ef course, make my pointer move. But this movement is synthetic, if I were to use AHI to detect my mouse device. Could I turn those synthetic movements made with AHK into more 'organic' ones? Like if they were done by hand. If that's the case, I'll probably start playing with AHI and have followup questions once I start testing stuff.

Thanks a lot!
g0dArthas
Posts: 2
Joined: 12 Jul 2021, 00:52

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

13 Jul 2021, 10:08

Follow up question.
I read the documentation more extensively now and would like to clarify what I want to do exactly. From what I understand, I could get the mauseId of the device I'm using (it's a laptop, so I'm guessing mause devices will show the mause I use and probably the touchpad too). Then I could "AHI.SendMouseMove(<mouseId>, <x>, <y>)" to hide the event from windows to see it, correct?
That's kind of what I want to do, but what that function does is hide the movements of my mouse device and that's not exactly what I need, what I need is to hide the event I'm making using DllCall("mouse_event"). Is that possible? Can I hide a synthetic mause_event not made by any device, just script made?
StJudas
Posts: 1
Joined: 28 Jul 2021, 14:10

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

28 Jul 2021, 14:28

Hi, Thank you for make AHI, it is amazing.

I am new here and sorry for my simple question.

Can I remap keys for 2 different keyboard (keyboard 2 and keyboard 3) in 1 script.

If yes,can I please have example

Thank you very much.
mmelon
Posts: 12
Joined: 22 Jul 2019, 12:50

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

05 Aug 2021, 03:55

Hi,

I am creating hotkeys using the hotkey command that call a label. Inside the label I want to record the device that pressed the key.

if(cm2.IsActive) {
device := "keyboard2"
}

doesn't work well. Presumably because when the label is reached, the isactive status of cm2 has expired.

Does anyone know a better way?
mmelon
Posts: 12
Joined: 22 Jul 2019, 12:50

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

08 Aug 2021, 07:49

does anyone know if

AHI.SendKeyEvent(keyboardId, GetKeySC(key), state)

can respect Sendlevel?

I think my other hotkeys aren't being triggered by SendKeyEvent because the sendlevel isn't high enough.

It works when I use send with sendlevel 2.

Another question: When I send a key event does it set isActive for the appropriate device for use in context mode?

Return to “Scripts and Functions (v1)”

Who is online

Users browsing this forum: No registered users and 113 guests