Badger101
Member
- Joined
- Dec 14, 2020
- Messages
- 20
- Programming Experience
- Beginner
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 helpI 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:
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.
- 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.
I have attached code for an example form using SharpDX (install SharpDX.DirectInput from Nuget).
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?with my code i was able to move the mouse cursor with the joystick
the code you provided works with no errors but im not getting any actions
"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?isnt working
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.why are you writing console writeline
In works the same as yours (with quirks) for me, both moving and clicking.your code completely doesn't work
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).I can see the values x,y in debugger
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 towhen there is no movement (X 0 Y 0 with my pad)
if (!(state.X==0 && state.Y == 0))
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:DeviceClass.GameControl
is the same that you had in SlimDX.Debug.WriteLine(update.ToString());
in CheckBufferAndCurrentState) here and use dpad directions, what do you see?