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

Post your working scripts, libraries and tools
arti9m
Posts: 1
Joined: 20 Mar 2019, 09:40

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

20 Mar 2019, 09:57

AHI does not work with numpad slash for me.
In Monitor I can see State 2 and 3 instead of 0 and 1 for "/" key.
My script does nothing with that key, it does not call the callback function and it does not block input of this key.
Please help :)
Also, In the Monitor it says State 0 for press and 1 for release, but in actual AHK scripts it's the other way around.
Script code:
Screenshot of AHI Monitor:
User avatar
evilC
Posts: 4717
Joined: 27 Feb 2014, 12:30

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

20 Mar 2019, 12:12

NumpadDiv is code 309, not 53
It's an extended keycode, so you have to add 256 to the normal number
GetKeySC() gives the correct keycode for that key

That is the old monitor - it shows the raw value that comes from Interception, which is 1 for release and 0 for press for normal keys, or 2/3 for extended keys

Subscription functions get passed 1 for press, 0 for release

The next release of AHI has a reworked monitor that shows what you would see when subscribing
serzh82saratov
Posts: 71
Joined: 01 Jul 2017, 03:04

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

21 Mar 2019, 03:15

Hotkey with ContextManager is not always reliable, it quickly resets the IsActive parameter, and it happens that the keystroke is not blocked.

I changed OnContextCallback, and set the ContextManager for all keyboards. Now one of my variables is set to the value of the keyboard ID, and is not reset, so it works reliably.

Code: Select all

	class ContextManager {
		IsActive := 0
		__New(parent, id){
			this.parent := parent
			this.id := id
			
			result := this.parent.Instance.SetContextCallback(id, this.OnContextCallback.Bind(this, id))
		}
		
		OnContextCallback(id, state) {
			If !state
				return
			Keyboard := id
		}

Global Keyboard

#If Keyboard = 1
1::MsgBox 1
#If Keyboard = 2
1::MsgBox 2
#If Keyboard = 3
1::MsgBox 3
#If
But now the emulated input "SendInput {1}" starts the hotkey of the last keyboard.

I know that AHKHID responds to SendInput, and writes 0 to the input device.
Can you add ContextManager2? It will subscribe to all devices at once, and just set the variable to the device number, and in the case of emulation to zero.

UPD: Do this separately for mice and keyboards.
User avatar
evilC
Posts: 4717
Joined: 27 Feb 2014, 12:30

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

21 Mar 2019, 08:08

Interception will not see anything that AHK sends, as AHK only synthesizes input at the OS level, and Interception sits below that at the driver level.
Hotkey with ContextManager is not always reliable, it quickly resets the IsActive parameter
Not sure what you are saying here - once in the AHK hotkey, it should not matter if the IsActive param gets reset immediately (In fact it is desirable).
As long as the context-sensitive hotkey is firing, it's doing it's job.
I would also not make it use global variables, there is no need, you could store Keyboard as a class property instead.
serzh82saratov
Posts: 71
Joined: 01 Jul 2017, 03:04

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

21 Mar 2019, 08:32

Do not really understand.
Why then there are gaps of pressing, about 1 out of 50, even in a simple condition.

Code: Select all

#if cm1.IsActive
In this embodiment, much more often. Since the cm1.IsActive is checked first, and cm2.IsActive will be already empty.

Code: Select all

#if cm1.IsActive || LongExp()
1::MsgBox 1
#if cm2.IsActive || LongExp()
1::MsgBox 2
#if

LongExp() {
 	Sleep 20
}
Last edited by serzh82saratov on 21 Mar 2019, 08:41, edited 1 time in total.
serzh82saratov
Posts: 71
Joined: 01 Jul 2017, 03:04

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

21 Mar 2019, 08:39

I also wanted to ask why OnContextCallback is called 4 times for each click? state - 1010
User avatar
evilC
Posts: 4717
Joined: 27 Feb 2014, 12:30

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

21 Mar 2019, 08:45

Ahh, I see, I will need to look into that to see if I can work out why it may be happening.
OnContextCallback should be called before and after each key event (Before press, after press, before release, after release)
serzh82saratov
Posts: 71
Joined: 01 Jul 2017, 03:04

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

27 Mar 2019, 14:29

Do not really understand.
Why then there are gaps of pressing, about 1 out of 50, even in a simple condition.
Maybe pressure gets in 1010 - (Before press, after press, before release, after release)
ppapkor
Posts: 4
Joined: 30 Jan 2019, 03:22

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

28 Mar 2019, 01:16

Included monitor app doesn't capture synthesized mouse signal.
mouses's original hardware signals captured nicely, but only synthesized 'mouse' signal doesn't appear on the monitor app.
* synthesized mouse movement and click are fine. just it doesnt appear on the monitor.

if synthesized signal is perfectly same with original hardware signal, should it be captured by monitor app?
User avatar
evilC
Posts: 4717
Joined: 27 Feb 2014, 12:30

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

28 Mar 2019, 05:30

ppapkor wrote:
28 Mar 2019, 01:16
Included monitor app doesn't capture synthesized mouse signal.
...

if synthesized signal is perfectly same with original hardware signal, should it be captured by monitor app?
No, synthesized input should not be seen by the app.
The app shows what Interception sees, and it does not see what it sends
habibi
Posts: 5
Joined: 15 Apr 2019, 14:19

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

15 Apr 2019, 16:16

Thank you keep supporting this awsome project
I made simple test script for reducing recoil in fps games
Just replaced dallcall mouse event to AHI.SendMouseMove
When I checked Monitor.ahk, both mouse move events are displayed, which is my mouse move and AHI script move (when dllcall, mouse move event never showed up)
Question is am I use AHI correctly? Because I can't say i'm fully understand :(
Goal is avoid Dllcall event and make scripted move looks like raw-input

And test script seems almost works fine but when variable x or y is not the number, Error window pops out
Description is "Error in #include file \Lib\AutoHotInterception.ahk 0x80004002 interface is not supported"
This thing never happen when i use normal AHK commands
After same fix,I could avoid this error. But Can i fix this problem?



Code: Select all

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

global AHI := new AutoHotInterception()
global mouseid := AHI.GetMouseId(HID, VID)

no_pattern :={} ; cause error when using "|| a_index > active_pattern.maxindex()"
a_pattern := {1: "10,10",  2: "0,10",  3: "-10,10"
             ,4: "20,20", 5: "0,20", 6: "20,20" ,7: "0,0"}

active_pattern:=no_pattern

1::
active_pattern:=a_pattern
return

3::
sleep 10
loop % active_pattern.maxindex() ; added :fix error
{
x:=strsplit(active_pattern[a_index],",")[1]
y:=strsplit(active_pattern[a_index],",")[2]
AHI.SendMouseMoveRelative(mouseid, x, y)
sleep, 150
} until !GetKeyState(3,"P")  ; || a_index > active_pattern.maxindex() ----removed :cause error
sleep 500
return

^Esc::
	ExitApp
User avatar
evilC
Posts: 4717
Joined: 27 Feb 2014, 12:30

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

16 Apr 2019, 04:13

I am surprised that script works at all, as you are not supplying VID or PID on this line global mouseid := AHI.GetMouseId(HID, VID)
HID is unset
VID is unset
I have no idea why you used the variable names HID and VID instead of VID and PID
habibi
Posts: 5
Joined: 15 Apr 2019, 14:19

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

16 Apr 2019, 05:40

Sorry I just edit that line before post :) and Var name is just mistake
actual script has my VID & PID
User avatar
evilC
Posts: 4717
Joined: 27 Feb 2014, 12:30

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

16 Apr 2019, 06:42

Also, why are you doing a stringsplit all the time? Use an array of arrays:

Code: Select all

#include Lib\AutoHotInterception.ahk

global AHI := new AutoHotInterception()
global mouseid := AHI.GetMouseId(HID, VID)

no_pattern :={} ; cause error when using "|| a_index > active_pattern.maxindex()"
a_pattern := [[10, 10], [0,10], [-10, 10], [20, 20], [0, 20], [20,20], [0,0]]

active_pattern:=no_pattern

1::
active_pattern:=a_pattern
return

3::
sleep 10
loop % active_pattern.maxindex() ; added :fix error
{
x := active_pattern[A_Index][1]
y := active_pattern[A_Index][2]
AHI.SendMouseMoveRelative(mouseid, x, y)
sleep, 150
} until !GetKeyState(3,"P")  ; || a_index > active_pattern.maxindex() ----removed :cause error
sleep 500
return
habibi
Posts: 5
Joined: 15 Apr 2019, 14:19

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

16 Apr 2019, 10:36

Oh thank you, i just didn't know smart method
So could I know your opinion
habibi
Posts: 5
Joined: 15 Apr 2019, 14:19

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

16 Apr 2019, 11:27

Thank you.
Is the way of using AHI.SendMouseMoveRelative correct?
habibi
Posts: 5
Joined: 15 Apr 2019, 14:19

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

16 Apr 2019, 12:44

Much appreciated :)
This is awesome ! exactly what i want
kyuuuri
Posts: 204
Joined: 09 Jan 2016, 19:20

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

30 Apr 2019, 15:42

Hello, I've been trying to achieve something like this:

Code: Select all

$q::
if GetKeyState("q", "p")
{
	send {q}
	sleep, 50
}
return
But using Interception. My problem is that when I hold down Q, the key is sent by Interception and the scripts detects it's own keystroke so they loop goes crazy.
Is there any workaround for Interception like the "$" option in AHK?

Return to “Scripts and Functions”

Who is online

Users browsing this forum: gwarble and 76 guests