Here you can see me subscribing to the same controller via DirectInput and XInput at the same time, and operating the triggers.
When reading an XBox controller via DirectInput (or WinMM which AHK uses), the triggers are merged into one axis, whereas with XInput you can see me subscribe to two axes and get individual reports.
Github Page
Download
So this something I have been trying to achieve for like 5 years - full capability joystick support with no need for polling loops in your code.
This uses a C# DLL which wraps the SharpDX library, for reading of stick data via DirectInput and XInput.
Whenever a stick changes, a function in your AHK code is called.
Simple usage example:
Download release from github page, extract to a folder, then double-click one of the demo scripts (MonitorDemo.ahk or SimpleExample.ahk)
To write your own scripts, follow what SimpleExample.ahk does - you need to add the following lines to the start of your script:
Code: Select all
#Include JoystickWrapper.ahk
jw := new JoystickWrapper("JoystickWrapper.dll")
You can call jw.GetAnyDeviceGuid() to get GUID of the first stick it finds, or call jw.GetDevices() to get a list of available devices - see MonitorDemo.ahk for how to do this.
A GUID will look like this: guid := "da2e2e00-19ea-11e6-8002-444553540000"
Once you have your stick GUID, you can subscribe to a button, axis or POV on the stick using one of the following commands:
Code: Select all
jw.SubscribeAxis(guid, 1, Func("TestFunc").Bind("Axis"))
jw.SubscribeButton(guid, 1, Func("TestFunc").Bind("Button"))
jw.SubscribePov(guid, 1, Func("TestFunc").Bind("Pov"))
So, putting that all together, you might end up with something like:
Code: Select all
#persistent
#Include JoystickWrapper.ahk
jw := new JoystickWrapper("JoystickWrapper.dll")
;guid := "da2e2e00-19ea-11e6-8002-444553540000"
if (guid := jw.GetAnyDeviceGuid()){
jw.SubscribeAxis(guid, 1, Func("TestFunc").Bind("Axis"))
jw.SubscribeButton(guid, 1, Func("TestFunc").Bind("Button"))
jw.SubscribePov(guid, 1, Func("TestFunc").Bind("Pov"))
} else {
MsgBox "No sticks found"
ExitApp
}
TestFunc(type, value){
Tooltip % type ": " value
}
^Esc::
ExitApp