[null, null, {"document_url": "http://settorezero.blogspot.com/2010/11/using-joysticks-from-vbnet.html", "unformatted_src": "http://2.bp.blogspot.com/__3_TdkFnhGo/TOw3793T8YI/AAAAAAAAAhY/SPeNZFFcLU8/s1600/aggiungere_riferimento_a_directx.png", "src": "http://2.bp.blogspot.com/__3_TdkFnhGo/TOw3793T8YI/AAAAAAAAAhY/SPeNZFFcLU8/s1600/aggiungere_riferimento_a_directx.png", "formatted_filename": "aggiungere riferimento a directx"}, null, null, {"document_url": "http://settorezero.blogspot.com/2010/11/using-joysticks-from-vbnet.html", "unformatted_src": "http://1.bp.blogspot.com/__3_TdkFnhGo/TOw5FBUqh8I/AAAAAAAAAhg/vb-00bpU0b4/s1600/imports_directx.png", "src": "http://1.bp.blogspot.com/__3_TdkFnhGo/TOw5FBUqh8I/AAAAAAAAAhg/vb-00bpU0b4/s1600/imports_directx.png", "formatted_filename": "imports directx"}, null, null, null, null]

Using Joysticks from VB.NET

There are several ways for using joystick on VB.NET: APIs and DirectX. Here I'll show you the DirectX Method.

First, download DirectX SDK from Microsoft:
and then install it.

Starts a new project on VB.NET and add a reference to DirectX:
Project -> Add reference.
Select Microsoft.DirectX.DirectInput from list in ".NET" tab: First thing to do is obtain a device list, but VB.NET will throw an exception (Loader Lock). Deactivate Loader Lock exception from menu Debud -> Exceptions. Explode "Managed Debugging Assistant", find "Loader Lock" and uncheck the box "Generated": Imports DirectInput name space at top of your program: Add a timer (timer1) on your form and set "Enabled" property on true (we'll use it for joystick polling).
Add a textbox named txtDir
Add a textbox named txtButtons
The code is the following:

state object will contain all informations you need. State.X is the X position of joystick (type state followed by dot and see the entire list of controls).

the GetButtons property of state object will give you the state of buttons. GetButtons give an array.

if the value is 128, the button is pressed, if the value is 0 the button isn't pressed or doesn't exists
Posted by CyB3rn0id at 11:08 PM Labels: directx, joypad, joystick, v.net
