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

Post your working scripts, libraries and tools for AHK v1.1 and older
User avatar
evilC
Posts: 4822
Joined: 27 Feb 2014, 12:30

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

Post by evilC » 30 Jan 2015, 09:54

Note: This project should still be considered Work-In-Progress and is not ready for general use yet.

Note: Requires AHK >= 1.1.20.00

About
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.
ToDo:
  • 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

Image
Last edited by evilC on 10 Mar 2015, 09:38, edited 21 times in total.

User avatar
Soft
Posts: 174
Joined: 07 Jan 2015, 13:18
Location: Seoul
Contact:

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

Post by Soft » 06 Feb 2015, 02:54

I know next to nothing about the AHK HID...
May I ask you what is the purpose and benefits by using ~HID?
AutoHotkey & AutoHotkey_H v1.1.22.07

User avatar
evilC
Posts: 4822
Joined: 27 Feb 2014, 12:30

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

Post by evilC » 06 Feb 2015, 03:55

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:
Image

User avatar
evilC
Posts: 4822
Joined: 27 Feb 2014, 12:30

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

Post by evilC » 26 Feb 2015, 20:37

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.

User avatar
evilC
Posts: 4822
Joined: 27 Feb 2014, 12:30

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

Post by evilC » 28 Feb 2015, 01:21

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).

User avatar
evilC
Posts: 4822
Joined: 27 Feb 2014, 12:30

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

Post by evilC » 07 Mar 2015, 16:06

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.

User avatar
evilC
Posts: 4822
Joined: 27 Feb 2014, 12:30

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

Post by evilC » 08 Mar 2015, 23:26

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.


blinkybill
Posts: 4
Joined: 28 Jun 2022, 21:04

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

Post by blinkybill » 06 Jul 2022, 20:04

hi @evilC,
is there a way i can use this to get just a list of connected joysticks with their names and InstanceGuid (not class guid)?
i mean i need the names as they appear in the registry:
HKEY_CURRENT_USER\System\CurrentControlSet\Control\MediaProperties\PrivateProperties\Joystick\OEM

i found a program that does this(device lister) but is written in c#:
https://github.com/briankendall/devreorder/releases

and this reference shows how to get Instance GUID in c#
https://docs.microsoft.com/en-us/dotnet/api/system.guid?redirectedfrom=MSDN&view=net-6.0

but i didn't find anything about getting Instance GUID in AHK.

Post Reply

Return to “Scripts and Functions (v1)”