Question getting Dpad to work using slimDX

Badger101

Member
Joined
Dec 14, 2020
Messages
20
Programming Experience
Beginner
im using slimdx for directx input i got the buttons to work and joystick but i cant get the dpad to work if d pad left pressed it moves cursor to left if right pressed move cursor right ,etc
 

Attachments

  • code.txt
    3.8 KB · Views: 40
I haven't used DX of any kind before, but I tested your code and it works for me. My gamepad has a toggle button for dpad and left analog stick, if yours have that too check if you get response from either.

There are a few issues with the code that doesn't affect operations, but I'll mention them:
  • You have redundant GetSticks calls in constructor (line 2 without using return) and form load.
  • As this is unmanaged objects you should make sure to dispose them, output when form closes shows 4 undisposed objects.
  • Logic for button down/up isn't right, it only acts when button is pressed and repeats, and not like once down & up, see my example attached for how I solved that.
Further SlimDX is marked deprecated by Nuget (last updated 2013), SharpDX is recommended as replacement. SharpDX is newer and very similar, it was also stopped being developed/maintained in 2019, but I haven't found another library.
I have attached code for an example form using SharpDX (install SharpDX.DirectInput from Nuget).
 

Attachments

  • code2.txt
    3.3 KB · Views: 31
I haven't used DX of any kind before, but I tested your code and it works for me. My gamepad has a toggle button for dpad and left analog stick, if yours have that too check if you get response from either.

There are a few issues with the code that doesn't affect operations, but I'll mention them:
  • You have redundant GetSticks calls in constructor (line 2 without using return) and form load.
  • As this is unmanaged objects you should make sure to dispose them, output when form closes shows 4 undisposed objects.
  • Logic for button down/up isn't right, it only acts when button is pressed and repeats, and not like once down & up, see my example attached for how I solved that.
Further SlimDX is marked deprecated by Nuget (last updated 2013), SharpDX is recommended as replacement. SharpDX is newer and very similar, it was also stopped being developed/maintained in 2019, but I haven't found another library.
I have attached code for an example form using SharpDX (install SharpDX.DirectInput from Nuget).
the code you provided works with no errors but im not getting any actions,, with my code i was able to move the mouse cursor with the joystick and if the cursor was over a button i would be able to select it with gamepad button im understanding the diffrence in the code but my attempts to change it to work for what i need isnt working please help
 

Attachments

  • code3sharpdx.txt
    3.5 KB · Views: 19
with my code i was able to move the mouse cursor with the joystick
Now I'm confused, in opening post you said your code wasn't working for moving the mouse with dpad. Now it does? So what is the problem with your code?
the code you provided works with no errors but im not getting any actions
isnt working
"Isn't working" is not a sufficient description for anything. In my code added a few Console.Writelines for debugging, what are you seeing in Immediate Window? Did you hook up the events for Form Load/Closing and timer Tick events? (and button Click if you use that) Did you uncomment line 63 that outputs the X/Y values?
 
Yes I hooked up the event properly and the timer and tried uncommenting line 63 but why are you writing console writeline I'm using Windows forms nothing come up when I uncommenting line 63 in my window I have a form with 2 buttons when I run my code slim dx you can move the mouse cursor with joystick and mouse stays in bounds of window and when cursor is over a button you can click it with gamepad but your code when I run it doesn't do anything doesn't move mouse or keep it in window bounds or allow me to click on any buttons your code completely doesn't work
 
why are you writing console writeline
To see debug information in Immediate Windows in Visual Studio as explained. I see output for device detection and click behaviour, and X/Y information if I want to see it.
your code completely doesn't work
In works the same as yours (with quirks) for me, both moving and clicking.
 
I couldn't get any information x,y with console.writeline just my regular form window comes up but If I put Debug.Log I can see the values x,y in debugger but the values x,y don't change with joystick movement I have tried reinstalling sharpDX same results
 
I do have the option "Redirect all output to Immediate Window" enabled, if you don't the output goes to Output Window.
I can see the values x,y in debugger
That is something. Remember there is one output line each timer Tick, which is 10 lines per second by default, try holding dpad left/right/up/down for a while to see repeated values for those directions, that will show the border values, mine will trigger values exactly at the set ranges +/-100. The if statement is to avoid setting cursor for the huge amount of poll times when there is no movement (X 0 Y 0 with my pad).
 
when there is no movement (X 0 Y 0 with my pad)
If you have the same zero position (X 0 Y 0 ) and have different direction values than +/-100 you could also swap the if statement to if (!(state.X==0 && state.Y == 0))
 
I figured out the problem I'm trying to use a 2.4 GHz wireless remote that has a USB plug in that's a receiver for the gamepad that doesn't work with your code but a USB wired gamepad work,s with your code, I'm not sure why that makes a difference??
 
Line 40 at input.GetDevices, try changing first argument to DeviceClass.GameControl, which is the comparable type and value you used in SlimDX. In code I posted I used DeviceType, which is a more specialized enum, I'm sure you can find a DeviceType value that works for the wireless pad also. Here you can see a comparison table of those enums for both libraries:
1609501940999.png
1609501954466.png


Curiously, my USB gamepad is also detected as DeviceType.Joystick (and .ControlDevice), but not as DeviceType.Gamepad :)
 
I got the gamepad button pressed working by changing DeviceType to gamepad instead of joystick but the Dpad for moving the cursor doesn't work and I tried all the other device types still not working for moving the mouse cursor and I can't figure out why
 
DeviceClass.GameControl is the same that you had in SlimDX.

"doesn't work"/"not working" is not an accurate description. So when you try to output X/Y you get no output, or only 0/0? If you get 0/0 and filter those out you don't get any output?

I'm also attaching updated code here that includes:
  • using buffered state updates for button, which makes that a whole lot easier (and still using current state for dpad) Buffered and Immediate Data
  • removing mouse_event and uses SendInput API according to MS documentation which says "Note This function has been superseded. Use SendInput instead."
The buffer may make your debugging easier because it will report all state changes and not just current state. Try uncomment line 68 (Debug.WriteLine(update.ToString()); in CheckBufferAndCurrentState) here and use dpad directions, what do you see?
 

Attachments

  • code3.txt
    4.2 KB · Views: 13
Back
Top Bottom