0

I am currently writing a .Net DirectInput wrapper DLL to allow event-based reporting of stick input from other languages (I am using AutoHotkey).
I currently use SharpDX to read stick data, but SharpDX only seems to report how many axes a stick reports, not which axes a stick reports.
For example, it is entirely possible for a stick to have 7 axes, but no X axis (You can see this by installing vJoy and configuring which axes it has - in the vJoy configuration utility, untick the X axis. Notice in joy.cpl that the X axis is gone).
Reading the stick caps via SharpDX (Using eg SharpDX.DirectInput.Joystick.Capabilities.AxeCount), there seems to be no way to tell that the missing axis is X.
Is the underlying DirectInput API able to represent this info, or would I have to go to something like RawInput to get at this info?

Clive Galway
  • 482
  • 4
  • 13
  • Ah, I notice that `Joystick.GetObjectPropertiesByName("X")` appears to query for the existence of axis X. it seems to throw an exception though? VS Autos window shows "'test.Deadzone' threw and exception of type 'SharpDX.SharpDXException'", although I see no exception thrown in my code, I guess it may be caught or something. Is it safe to do this? – Clive Galway Mar 14 '17 at 19:56

1 Answers1

1

So I worked this one out for myself.

Using SharpDX, you can use Joystick.GetObjectPropertiesByName("X") where "X" is the name of an axis. You can call ToString() on a JoystickOffset to get the name of the axis.
If you do this in a try block, then if it hits the catch, that axis does not exist on that stick.

Clive Galway
  • 482
  • 4
  • 13
  • Thanks, using this solution. I would like to clarify the answer a little. Calling GetObjectPropertiesByName() is not what throws, it is the attempt to access one of the properties on the returned ObjectProperties that will throw. It's mentioned in the OP's comment, but got lost in the final answer. – Joe Kolodz Sep 13 '21 at 12:46