GPWiki.org
GPWiki.org
It is currently Wed Jun 19, 2013 9:12 am

All times are UTC




Post new topic Reply to topic  [ 10 posts ] 
Author Message
PostPosted: Wed Aug 03, 2011 10:35 pm 
Novice

Joined: Wed Aug 03, 2011 10:23 pm
Posts: 7
Hi

I have a Windows forms application which manages a lot of keyboard shortcuts and I would like to add game pad support as well.

I couldn't access the Microsof.DirectX namespace so I installed the June 2010 DirectX SDK. I then open my project in Visual Basic 2010 and try to add references to the DLLs that it installed to C:\Program Files\Microsoft DirectX SDK (June 2010)\Developer Runtime\x86\

However when I select any of these files it gives me an error: "A reference to <file path> could not be added. Please make sure that the file is accessible, and that it is a valid COM component.

Am I just being thick? I'm not the most experienced programmer but I like to think I'm reasonably competent with VB so to fall at the first hurdle is a bit embarassing!

Any help would be greatly appreciated. Thanks in advance.


Top
 Profile  
 
PostPosted: Thu Aug 04, 2011 12:59 pm 
Mumbo Jumbo
User avatar

Joined: Fri Aug 20, 2004 1:15 pm
Posts: 804
Location: Michigan, USA
I don't have 2010 but in 2008 you click Add Reference, then on the .NET tab scroll down to Microsoft.DirectX

if you want to work with input devices, choose both the .DirectX and the .DirectInput items.

_________________
The path to hell is paved with clever code.


Top
 Profile  
 
PostPosted: Thu Aug 04, 2011 1:40 pm 
Novice

Joined: Wed Aug 03, 2011 10:23 pm
Posts: 7
Hi Mogolor

That's the first place I looked - it's not there.

Is it possibly because I'm running Windows 7 x64?


Top
 Profile  
 
PostPosted: Thu Aug 04, 2011 5:24 pm 
Mumbo Jumbo
User avatar

Joined: Fri Aug 20, 2004 1:15 pm
Posts: 804
Location: Michigan, USA
i have 64-bit windows 7.

try re-installing the directx sdk

_________________
The path to hell is paved with clever code.


Top
 Profile  
 
PostPosted: Thu Aug 04, 2011 6:20 pm 
Novice

Joined: Wed Aug 03, 2011 10:23 pm
Posts: 7
I downloaded Microsoft.DirectX.DirectInput.dll from: http://www.dalehay.com/utilities/micros ... ut.dll.php

It allowed me to add a reference but I haven't had a chance to play with it yet... I'll report back soon.


Top
 Profile  
 
PostPosted: Sun Aug 07, 2011 12:05 pm 
Novice

Joined: Wed Aug 03, 2011 10:23 pm
Posts: 7
I managed to find the proper location for the DirectInput DLL's: C:\Windows\assembly\GAC\Microsoft.DirectX.DirectInput\1.0.2902.0__31bf3856ad364e35\Microsoft.DirectX.DirectInput.dll

However I'm still struggling to get started with it.

Has DirectX been deprecated in favor of XNA and should I be using that instead?

Can I get controller input directly in VB or will I need to create a C# or C++ class library?


Top
 Profile  
 
PostPosted: Sun Aug 07, 2011 10:32 pm 
Dexterous Droid
User avatar

Joined: Wed Aug 18, 2004 7:40 pm
Posts: 3746
Location: South Africa
DirectX isn't deprecated but XNA is a lot easier to get into.

Apparently you should use XInput for controller input but I'm not sure on that. XNA also has an easy way to get 360 controller input.

Also, if you're manually having to download the directx dll you're probably doing something wrong. Try reinstall the SDK, is the only thing I can think of. The entries should be added to the list of possible References if DX SDK is correctly installed.

_________________
Whatever the mind can conceive and believe, it can achieve


Top
 Profile  
 
PostPosted: Mon Aug 08, 2011 3:09 pm 
Novice

Joined: Wed Aug 03, 2011 10:23 pm
Posts: 7
I need to support a wide range of game pads so XNA is not an option unfortunately.

I think I have found why I am having trouble in VS2010. I found this in the release notes for the Feb 2010 (second most recent) DirectX SDK release notes:

Quote:
In the next release, the DirectX SDK will add support for Visual Studio 2010. At that time, the DirectX SDK will no longer support Visual Studio 2005; the February 2010 release will be the last release to support Visual Studio 2005. The next release will continue to support Visual Studio 2008.


And it appears that they did NOT add support for VS2010 in the most recent (June) release, which is the one I have.

I am downloading VS2008 now...


Top
 Profile  
 
PostPosted: Mon Aug 08, 2011 5:29 pm 
Mumbo Jumbo
User avatar

Joined: Fri Aug 20, 2004 1:15 pm
Posts: 804
Location: Michigan, USA
i like 2008 better anyway.

_________________
The path to hell is paved with clever code.


Top
 Profile  
 
PostPosted: Wed Aug 24, 2011 6:47 pm 
Octogenarian

Joined: Thu Aug 04, 2011 12:00 am
Posts: 87
Location: Arizona
Here are a pair of classes that will help you with DirectInput. This assumes you already have the DirectInput reference in your project. I do have an example using XInput in C++, but not VB.

DirectInput Keyboard Class
Spoiler: show
Imports Microsoft.DirectX
Imports Microsoft.DirectX.DirectInput

Public Class CKeyboard

Private ref_form As Windows.Forms.Form
Private p_keyboard As DirectInput.Device
Private p_keystate As DirectInput.KeyboardState


Public Sub New(ByRef frm As Windows.Forms.Form)
ref_form = frm
End Sub

Public Function Init() As Boolean
Try
'create new keyboard device
p_keyboard = New DirectInput.Device(DirectInput.SystemGuid.Keyboard)

'set cooperative level for keyboard
Dim cooplevel As CooperativeLevelFlags = _
CooperativeLevelFlags.Background Or _
CooperativeLevelFlags.NonExclusive

p_keyboard.SetCooperativeLevel(ref_form, cooplevel)

'try to acquire the keyboard
p_keyboard.Acquire()

'initialize key state
Poll()

Return True

Catch ex As Exception
Return False
End Try
End Function

Public Sub Poll()
p_keystate = p_keyboard.GetCurrentKeyboardState()
End Sub

Public Function KeyState(ByVal key As Microsoft.DirectX.DirectInput.Key) As Boolean
Return p_keystate(key)
End Function

Protected Overrides Sub Finalize()
MyBase.Finalize()
p_keyboard.Unacquire()
p_keyboard.Dispose()
p_keyboard = Nothing
End Sub
End Class


DirectInput Mouse Class
Spoiler: show
Imports Microsoft.DirectX
Imports Microsoft.DirectX.DirectInput

Public Class CMouse

Private p_mouse As DirectInput.Device
Private p_mousestate As DirectInput.MouseState
Private buttons() As Byte

Public Sub New(ByRef frm As Windows.Forms.Form)
Try
'create new mouse device
p_mouse = New DirectInput.Device(SystemGuid.Mouse)

'set cooperative level for mouse
Dim cooplevel As CooperativeLevelFlags = _
CooperativeLevelFlags.Background Or _
CooperativeLevelFlags.NonExclusive
p_mouse.SetCooperativeLevel(frm, cooplevel)

'try to acquire the mouse
p_mouse.Acquire()

Catch ex As Exception
MessageBox.Show("Error initializing mouse", "DirectInput Error")
End Try

End Sub

Public Sub Poll()
p_mousestate = p_mouse.CurrentMouseState
buttons = p_mousestate.GetMouseButtons()
End Sub

Public Function Button() As Integer
If (buttons(0) > 0) Then
Return 1
ElseIf (buttons(1) > 0) Then
Return 2
ElseIf (buttons(2) > 0) Then
Return 3
Else
Return 0
End If
End Function

Public Function X() As Integer
Return p_mousestate.X()
End Function

Public Function Y() As Integer
Return p_mousestate.Y()
End Function

Public Function Wheel() As Integer
Return p_mousestate.Z
End Function

Public Sub Dispose()
p_mouse.Unacquire()
p_mouse.Dispose()
End Sub

End Class

_________________
Amazon Author Page
Game Dev Forum
Facebook Page


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 10 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group