Page 1 of 1

[WIP] CHID - 8 Axis, 128 Button, 4 POV Joystick Input

Posted: 30 Jan 2015, 09:54
by evilC
Note: This project should still be considered Work-In-Progress and is not ready for general use yet.

Note: Requires AHK >=

CHID is an attempt to provide an alternative to AHK's joystick support, with the following improvements:
  • 8 axes per device (AHK supports 6)
  • 4 POV Hats per device (AHK supports 1)
  • 128 buttons per device (AHK supports 32)
  • Events for button up/down events (AHK supports down only)
  • Events for axis move (AHK does not support at all)
Current Features:
  • Decode WM_INPUT messages for Axes / Buttons / POVs.
  • Basic class wrapping.
    Class instance per device etc.
  • Axis / Button / Hat change callbacks with change delta
    One callback for each input type, array available with what changed.
  • Axis values are currently not all conformed to the same scale, and are pre calibration values.
  • Does not support hot-plugging of devices yet.
Github Page
Please use the Issues section on the GitHub page to check and report issues.

Compiled version of Demo


Re: [WIP] CHID - A classed replacement for AHKHID using _Str

Posted: 06 Feb 2015, 02:54
by Soft
I know next to nothing about the AHK HID...
May I ask you what is the purpose and benefits by using ~HID?

Re: [WIP] CHID - A classed replacement for AHKHID using _Str

Posted: 06 Feb 2015, 03:55
by evilC
As far as this project is concerned, HID is a method for USB devices to be interpreted by a computer without the need for a driver. It might have other uses, I dunno, I am new to HID myself.

HID can be used to read the keyboard and mouse, but frankly you are probably better off with other methods.
Unless of course you have devices with non-standard buttons, or want to use multiple keyboards at once, etc.

My primary goal for CHID is to replace AHK's ageing joystick support.

AHK uses the WinMM library to handle joystick input, and is subject to the following limitations:
Max 6 axes (Windows supports 8)
Max 1 POV hat (Windows supports 4)
?Max 32 Buttons? (Windows supports 128, even though the control panel widget only supports 32)
No "up events" (button release events) - ie 1Joy1 up:: will never trigger.
No events at all for axes (You have to run an endless GetKeyState() loop to handle stick input.

Here is a demo showing a full-capability stick being detected by CHID:

Re: [WIP] CHID - A classed replacement for AHKHID using _Str

Posted: 26 Feb 2015, 20:37
by evilC
Another major step forward. Tonight, HotkeyIt and I got reading of the "Preparsed Data" working for joysticks.

This means that it does not matter how many buttons or axes a device has, in theory we can now take that binary data and convert it into something meaningful like "button 55 is pressed".

At the moment, it looks like it could probably do with a bunch of optimization (it's sluggish), but it works.

I will add links to the OP for compiled and source.

Re: [WIP] CHID - A classed replacement for AHKHID using _Str

Posted: 28 Feb 2015, 01:21
by evilC
I did an optimization pass - down from ~1 second to process a WM_INPUT message to ~16ms.
It is now nice and responsive.

Just one known bug - if you hold buttons 1,2,3 and 4 - the output reads 1,9,2,9.
If you hold buttons 1-4, the returned data should look like 1,2,3,4, no matter what order you held the buttons in, so if our code is returning 1,9,2,9, the only possibly explanation I see for 2 being the 3rd element is that we are reading half as many bytes as we should do, or the elements of the returned data are twice as big as they should be.

I favor the latter, as in the C code we are following, the value is defined as USAGE usage[MAX_BUTTONS]; with USAGE being a USHORT.

But whatever, as a proof-of-concept it holds water. 16ms is not terrible, and we can make it even quicker I am sure (eg AHK_H's import technique to accelerate the DLL calls for a start).

Re: [WIP] CHID - Read All 8 Axes from Joysticks via RawInput

Posted: 07 Mar 2015, 16:06
by evilC
Major update.

A bunch of bugs have been fixed (Some that had been hacked around, so you would not notice any change), the code now also works properly on x64.

I added the beginnings of implementation of a class wrapper - devices are now wrapped in a class.
The demo code is still a bit untidy / hacky in places (setting a class property for output by the demo code), but it will suffice for now.

Processing speed for WM_INPUT messages is down to <3ms on my machine for a full capability stick - starting to get to a point where it would be usable. More speed increases could well follow (It should theoretically be possible to get all axes via one HidP_GetUsageValueArray DLL call, currently it is one DLL call per axis).

Sticks and Buttons basically seem all good (except for being pre-calibration values for the stick), but Hats still elude me. Shaul (the Author of vJoy) reckons things will fall into place one I get HidP_GetUsageValueArray working.

Re: [WIP] CHID - 8 Axis, 128 Button, 4 POV Joystick Input

Posted: 08 Mar 2015, 23:26
by evilC
CHID is now entering a "usable" state.

I have now implemented callbacks which fire on state change.
Button and axis change events are finally implemented!

I still have to implement converting axis values to a consistent, calibration-aware scale, but apart from POV hats, all the data for sticks is there and usable - ie it would be trivial to use CHID and CvJoyInterface to remap a physical to a virtual stick.

Re: [WIP] CHID - 8 Axis, 128 Button, 4 POV Joystick Input

Posted: 10 Mar 2015, 09:36
by evilC
Hat support has now been properly implemented. All 4 POV hats are now available for use.