How do I use forcefeedback on a gamepad in Visual Basic 2008?
I can only find things that relate to C++
Printable View
How do I use forcefeedback on a gamepad in Visual Basic 2008?
I can only find things that relate to C++
Hey,
Are you using XNA?
If so, the following may be of interest to you:
http://www.krissteele.net/blogdetails.aspx?id=153
Hope that helps!
Gary
Hey,
On that side I am not sure, I haven't really used XNA, I just know about it existence.
Gary
Ok, thanks.
I will have a look at XNA. If thats not successful, does anyone else know how I could achieve this in VB?
Anyone else got any ideas please?
I read something about using C++/# code (I think it was to do with DirectX) in a wrapper in VB.NET. What is a wrapper and how do I use it?
Hey,
A wrapper would be simply including the C# Library in your application and exposing the functionality of it through VB.Net.
Gary
which gamepad is it? Are you the guy who asked me about the xbox 360 gamepad?
gep13 - I thought that was the sort of idea. How do I go about doing this?
kleinma - It was an original xbox controller (not 360) but yes it was me who PM'ed you.
Thanks both
If that controller is compatible (it probably is) then it should be as easy as setting a reference to the Microsoft.Xna.Framework (you will need to first download and install XNA game studio 3.0 SDK which is free)
Once you do that, you will be able to set the above reference in your code.
Then (as far as sending rumble) it should be as simple as
the two 1 values being passed are for the left and right motor (assuming it has 2 vibration motors like the 360 controller does) I would imagine if it only has 1, then one of those values is ignored. The intensity of the vibration is any value from 0.0 (none) to 1.0 (max vibration)Code:GamePad.SetVibration(PlayerIndex.One, 1, 1)
I have done Tools -> Add reference -> Microsoft.XNA.Framework.
I then put the following code
But it says "Name 'GamePad' is not declared" and "Name 'PlayerIndex' is not declared".Code:Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
GamePad.SetVibration(PlayerIndex.One, 1, 1)
End Sub
What have I done wrong?
at the very top of your code (above the class definition), put this:
Code:Imports Microsoft.Xna.Framework
Imports Microsoft.Xna.Framework.Input
There seems to be no errors now but when I click the button the rumble does not activate.
It has been a little while since I have worked with it, and I was working with a controller that I knew was supported. However you could try running it in a loop and see if has any effect when you do that.
The application I used it for was polling, meaning it was constantly evaluating the controller state to apply whatever actions were needed.
Maybe it is the controller that is not supported - Im pretty sure that XNA is for Xbox 360 controllers. The one I'm using relies on DirectInput which I don't think the 360 needs??
XNA is basically a wrapper around DirectInput. XNA is actually a wrapper around DirectX. There is no such thing as "managed directx" anymore. It was merged into XNA.
I believe the XNA classes work with ANY device that supports direct input. The rumble thing COULD be different though.
Ok, sorry for my ignorance! =]
I will have another look at directinput, see what I can dig up. If you have any other ideas I would be very grateful.
Lets try something simple to start.
Try putting this in your code:
as you can see this is code for a button click event. So run your app and on your gamepad, hold down the A button, and then click the button on the form with the mouse. Which message does it give you?Code:Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
With GamePad.GetState(PlayerIndex.One)
If .Buttons.A = ButtonState.Pressed Then
MessageBox.Show("Button A is pressed")
Else
MessageBox.Show("Button A is NOT pressed, or this doesn't work")
End If
End With
End Sub
do you know if this controller is setup and installed correctly in Windows? Does it work in games? Does it show up in game controllers in the control panel?
The controller is set up fine. Windows recognises it and I already have some code in my project that gets data from the thumbsticks and recognises button presses.
Hey,
Can you post some of the code that you are already using? That may help.
Gary
The code I am using comes from the zip file on the 2nd post from here:
http://www.vbforums.com/showthread.php?t=583176
that code looks the same as what I gave you, so perhaps the original xbox controller simply does not support sending rumble commands. I know it has rumble abilities, but maybe it was something non standard when the original xbox came out. I know this all works fine with a 360 controller, because I have used them personally.
It definitely supports rumble because there is a program in the DirectX SDK that makes the controller rumble depending on where you have moved the mouse - the only problem is that it is written in C#/++ (not sure which) rather than VB.
Also, the XBCD driver that I am using has a little utility with it that allows you to activate the rumble. Come to think of it I think you can activate the rumble from the Windows game controllers control panel applet.
try using just this code to see if you get notifications of button presses when you press one of the A,B,X,Y buttons.
Code:Imports Microsoft.Xna.Framework
Imports Microsoft.Xna.Framework.Input
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim ControllerTimer As New Timer
ControllerTimer.Interval = 100
AddHandler ControllerTimer.Tick, AddressOf TimerTick
ControllerTimer.Start()
End Sub
Private Sub TimerTick(ByVal sender As Object, ByVal e As EventArgs)
If GamePad.GetState(PlayerIndex.One).Buttons.A = ButtonState.Pressed Then
MessageBox.Show("A button")
End If
If GamePad.GetState(PlayerIndex.One).Buttons.B = ButtonState.Pressed Then
MessageBox.Show("B button")
End If
If GamePad.GetState(PlayerIndex.One).Buttons.X = ButtonState.Pressed Then
MessageBox.Show("X button")
End If
If GamePad.GetState(PlayerIndex.One).Buttons.Y = ButtonState.Pressed Then
MessageBox.Show("Y button")
End If
End Sub
End Class
you sure you have the 2 import statements at the top?
The full qualification of the enum value is:
Microsoft.Xna.Framework.PlayerIndex.One
Aha, I missed one of the imports
I added it but still nothing. There are no errors reported but when I press buttons on the controller I dont get any messageboxes.
I thought "GamePad.GetState(PlayerIndex.One).Buttons.A" was to do with Xbox 360 controllers?
I came across this
I haven't actually got this code working but it looks hopeful. Does this mean anything to you?Code:applicationDevice.SendForceFeedbackCommand(ForceFeedbackCommand.SetActuatorsOn)
You are probably correct about the original controller not being supported by XNA. I took another look, and it isn't DirectInput that is required of the device, it is XInput (the replacement for DirectInput). So this means that XNA doesn't require the 360 controller per say, but it does require a controller that was built with xinput in mind, which I would imagine the companies that still make these devices for games (like logitech) support now in their new devices.
So it does look like to use the old XBOX controller, you would have to find or create some sort of DirectInput wrapper to expose it to .NET.
Or you know... you could get a 360 controller ;)
The code that I linked to in an earlier post, that's a DirectInput wrapper isn't it?
Presumably if I can get input from the controller there isn't much more that needs to be done to send force feedback commands too? (I believe force feedback is part of DirectInput)?
Ahh, I have just realised...
You posted earlier asking about the code I was using - I did a VERY stupid thing and gave you a link to this thread.
The thread I meant was this one:
http://www.xtremevbtalk.com/showthread.php?t=246406
The code I'm using is from the 2nd post on that thread, it's in a zip file.
Sorry!
I can't view the zip file because I am not a member there. If you want you can upload the zip here and I can look. My guess is it is either making direct calls to DirectX, or it is using MDX (managed direct x) which is now discontiuned in favor of XNA (Managed Direct X 2.0 was cancelled and rolled into XNA)
You can probably still get the 1.1 version of MDX though if you look around MS site for a download.
My code is identical to the attached code except I have added the following on the bottom:
Oh, and the code for button 1 doesnt work
Code:Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
applicationDevice.SendForceFeedbackCommand(ForceFeedbackCommand.SetActuatorsOn)
End Sub
Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
If labelButtons.Text <> ("") Then
Label3.Text = ("Success")
Else : Label3.Text = ("Fail")
End If
ill have a look, but can't really test anything until im home, where my controller is.
Ok, thank you very much =]
I downloaded the files from here and ran them and it worked:
http://www.codeproject.com/KB/direct...efeedback.aspx
In amongst those files is one called 'DirectInputWrapper.cs'
Is this what I need in terms of a wrapper? Could I use it and if so, how?
Any ideas?
Bump