Click here to Skip to main content
15,915,603 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
I want to use https://code.msdn.microsoft.com/windowsdesktop/DirectInput-Samples-8ac6f5e3[^][^]

the CustomFormat and Joystick is C++
I want to catch the value (X Axis or Y Axis) to send to C#

[Added from his new version of this "question"]

http://ezybot.blogspot.tw/2010/12/usb-joystick-c.html[^]
the sample can not use.
my visual studio express 2012 can not use it
WHY ?

and https://msdn.microsoft.com/en-us/library/windows/desktop/bb153252(v=vs.85).aspx[^]
I can run it . But no thing happen. I can not catch the X-Axis and Y-Axis value.
Posted
Updated 11-Jul-15 10:51am
v3
Comments
Member 11822709 11-Jul-15 23:42pm    
i have using Microsoft.DirectX.DirectInput;
http://ezybot.blogspot.tw/2010/12/usb-joystick-c.html

I run it and the here

private void iJoy_Load(object sender, EventArgs e) //iAdd
{
this.InitDevices();
}



this.InitDevices(); it happen error.
I use visual studio 2012 and 2008.run it

1 solution

Bad idea. It's much better and simpler to use DirectInput for .NET directly. Please start here:
https://msdn.microsoft.com/en-us/library/windows/desktop/bb153251%28v=vs.85%29.aspx[^],
https://msdn.microsoft.com/en-us/library/windows/desktop/ms805653.aspx[^].

Your first step will be adding a reference to DirectInput API to your code. Don't use COM references. You will need to use the library from GAC, for example, through the tab ".NET" of the Visual Studio "Add Reference" window; the item you will need to add is "Microsoft.DirectX.DirectInput".

Explore the library and MSDN, and you will find all you need. I used to develop the interface joystick in no time. Main idea you need to understand is using the hardware interrupt. Briefly speaking, you create a separate thread used to wait for input and the event wait handle to wait for. Such wait state does not consume any CPU time. You need register your event handle with the API; then your thread will be waken up by signalling on your event wait handle caused be a joystick hardware interrupt, which only happens when the user moves joystick, any of its levers or presses any of its buttons. You will be able to find it all in API easily.

—SA
 
Share this answer
 
v3
Comments
Stefan_Lang 20-Jul-15 3:40am    
If you have noticed incorrect statements or inappropriate advice, please point out the problematic parts and explain what is the problem, preferably with a link or other suitable way to proof your point.

Calling names is breaking this site's code of conduct and will ultimately only hurt you, not the OP: this comment was reported for abuse.
Sergey Alexandrovich Kryukov 20-Jul-15 8:55am    
Who you are talking to? This is a hatred attack with 75+ "comments" and editions (the abuser has been banned).
Thank you for reporting.
—SA
Stefan_Lang 20-Jul-15 9:16am    
Didn't realize he was on a hate campaign. I checked his profile and it looked innocent enough, and with almost 6 years of participation I didn't assume this comment style to be his usual standard...
Sergey Alexandrovich Kryukov 20-Jul-15 9:24am    
Right. Probably it was triggered by a single "Not an answer" note, as explained in my report to the forum. Crazy people sometimes hide the bugs in their head for much longer times. Can you imagine a person writing so many comments and editing answer signatures to make them look offensive and as many down-voted, all in a row?
—SA
Stefan_Lang 20-Jul-15 11:03am    
Yeah I know, some people just can't take criticism...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900