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
gregster
Posts: 9073
Joined: 30 Sep 2013, 06:48

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

Post by gregster » 22 Feb 2023, 13:50

ea5gtq wrote:
22 Feb 2023, 12:05
Please help with a script for two keyboards.
Does anyone have a sample?
What about the context mode example on the github repo? Did you try it?
Probably first initialize the library, like described further up - and determine your VID and PID which you want to use.

ea5gtq
Posts: 2
Joined: 22 Feb 2023, 06:52

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

Post by ea5gtq » 23 Feb 2023, 15:44

Your hint helped. Now both keyboards are detected and print different text with the same key. But unfortunately the program that runs first intercepts the priority.

bandicoot
Posts: 1
Joined: 17 Mar 2023, 15:29

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

Post by bandicoot » 17 Mar 2023, 15:54

Hello ,
I need some help someone give me this part of code ( Phasermaniac ) perhaps he take this from here big thanks to him and perhaps people who make it

Code: Select all

#include <AutoHotInterception>

AHIWrapper := new AutoHotInterception()
global AHI := AHIWrapper.GetInstance()

MouseId1:=13
MouseId2:=14

1JoyX:=0
1JoyY:=0
2JoyX:=0
2JoyY:=0

;P1---------------
1Joy1::
GetKeyState, 1JoyX, 1JoyX
GetKeyState, 1JoyY, 1JoyY
1JoyX:= 1JoyX*65535/100
1JoyY:= 1JoyY*65535/100
AHI.SendMouseButtonEventAbsolute(MouseId1, 0, 1, 1JoyX, 1JoyY)
KeyWait 1Joy1
AHI.SendMouseButtonEvent(MouseId1, 0, 0)
Return

1Joy2::
AHI.SendMouseButtonEventAbsolute(MouseId1, 1, 1, 1JoyX, 1JoyY)
KeyWait 1Joy2
AHI.SendMouseButtonEvent(MouseId1, 1, 0)
Return

1Joy3::
AHI.SendMouseButtonEventAbsolute(MouseId1, 2, 1, 1JoyX, 1JoyY)
KeyWait 1Joy2
AHI.SendMouseButtonEvent(MouseId1, 2, 0)
Return

;P2---------------
2Joy1::
GetKeyState, 2JoyX, 2JoyX
GetKeyState, 2JoyY, 2JoyY
2JoyX:= 2JoyX*65535/100
2JoyY:= 2JoyY*65535/100
AHI.SendMouseButtonEventAbsolute(MouseId2, 0, 1, 2JoyX, 2JoyY)
KeyWait 2Joy1
AHI.SendMouseButtonEvent(MouseId1, 0, 0)
Return

2Joy2::
AHI.SendMouseButtonEventAbsolute(MouseId2, 1, 1, 2JoyX, 2JoyY)
KeyWait 2Joy2
AHI.SendMouseButtonEvent(MouseId1, 1, 0)
Return

2Joy3::
AHI.SendMouseButtonEventAbsolute(MouseId2, 2, 1, 2JoyX, 2JoyY)
KeyWait 2Joy2
AHI.SendMouseButtonEvent(MouseId1, 2, 0)
Return

;EXIT---------------
F12::
	ExitApp
it works like it does ^^ , but could it be possible to have this to move mouse without push a key ? ( with for test and without hide cursor ?)
what I need to be clear , two gamepad who react like a mouse ;)
thanks


AbhishekAK
Posts: 2
Joined: 26 Aug 2023, 12:39

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

Post by AbhishekAK » 26 Aug 2023, 12:47

i wrote a script

Code: Select all

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

; Initialize AHI
AHI := new AutoHotInterception()

; Mouse
mouseId := AHI.GetMouseId(0x1532, 0x008A) ; Replace with your device VID/PID

; Keyboard
keyboardId := AHI.GetKeyboardId(0x1A2C, 0x2D43) ; Replace with your device VID/PID

; Buffer to store input events
global InputBuffer := []

; Subscribe to all buttons on the specific mouse
AHI.SubscribeMouseButtons(mouseId, true, Func("RecordMouseInput"))

; Subscribe to movement coming from the mouse
AHI.SubscribeMouseMove(mouseId, true, Func("RecordMouseMove"))

; Subscribe to all keys on the specific keyboard
AHI.SubscribeKeyboard(keyboardId, true, Func("KeyEvent"))

; Process delayed inputs
SetTimer, ProcessDelayedInputs, 1 ; Check for delayed inputs every 1ms

return

; Mouse
RecordMouseInput(button, state) {
    global InputBuffer
    InputBuffer.Push({Type: "MouseButton", Timestamp: A_TickCount, Button: button, State: state})
}

RecordMouseMove(x, y) {
    global InputBuffer
    InputBuffer.Push({Type: "MouseMove", Timestamp: A_TickCount, X: x, Y: y})
}

; Keyboard
KeyEvent(code, state){
    global InputBuffer
    InputBuffer.Push({Type: "Key", Timestamp: A_TickCount, Code: code, State: state})
}

ProcessDelayedInputs:
    delay := 7000 ; Set the delay to 0.5 seconds (500ms)
    while (InputBuffer.MaxIndex() > 0 && A_TickCount - InputBuffer[1].Timestamp >= delay) {
        input := InputBuffer.RemoveAt(1) ; Remove and get the first input in the buffer

        if (input.Type == "MouseMove") {
            AHI.Instance.SendMouseMove(mouseId, input.X, input.Y)
        } else if (input.Type == "MouseButton") {
            AHI.Instance.SendMouseButtonEvent(mouseId, input.Button, input.State)
        } else if (input.Type == "Key") {
            AHI.Instance.SendKeyEvent(keyboardId, input.Code, input.State)
        }
    }
return

^Esc::
    ExitApp
the problem is when running this and playing games the mouse movement is not 1 to 1 in 3D games. do you know why its not 1 to 1?


[Mod edit: Added [code][/code] tags. Please use them yourself when posting code.]

AbhishekAK
Posts: 2
Joined: 26 Aug 2023, 12:39

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

Post by AbhishekAK » 26 Aug 2023, 13:01

hello mod what do you think are the chances of evil c seeing my message and responding?

Post Reply

Return to “Scripts and Functions (v1)”