JoystickWrapper aims to bring event-based, full-featured reporting for Joysticks via a C# DLL.
It was written to overcome the limitations of joystick support in AutoHotkey – we did not have access to all axes and buttons, plus unlike hotkey bindings, it was not event-based (or the implementation was broken, as for buttons) you had to do polling loops.
Users can load the C# DLL in AutoHotkey using Lexikos’ CLR interop library, and with one simple function call, pass a Function Object (Or BoundFunc) which will get called when the subscribed input changes state, with the new value.
JoystickWrapper currently implements the DirectInput and XInput APIs via the SharpDX API.
It supports multiple subscriptions to the same input (You can optionally pass any string as an “Identifier”), as well as unsubscribing.
A Monitor Thread is started and stopped as appropriate – if nothing is subscribed, there will be no CPU usage.
Here are some GIFs show some AutoHotkey scripts subscribing to inputs and receiving updates:
In this demo, vJoy is used as an Input, as it allows easily replicating any capability joystick. I disable some axes, and check that the available axes reported via the DLL to the AHK script are correct.
This recording also demos the feature whereby you can subscribe to a direction of a POV hat on a DirectInput stick as if it were a button.
A little later in development, I add XInput support. 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.