Sign in to follow this  
chosendl

directinput keyboard ?

Recommended Posts

chosendl    122
Hi there, i cant seem to get the keyboard to work under directinput (i am using vb.net) Here is my code that i have already simplified, to try and isolate the problem. I get an error message on the setcooperativelevel line that says: ------------------------------------- An unhandled exception of type 'Microsoft.DirectX.DirectInput.InputException' occurred in microsoft.directx.directinput.dll Additional information: Error in the application. ------------------------------------- Imports Microsoft.DirectX.DirectInput Public Class Form1 Inherits System.Windows.Forms.Form #Region " Windows Form Designer generated code " Dim _device As Device Public Sub New() MyBase.New() 'This call is required by the Windows Form Designer. InitializeComponent() MyBase.Show() _device = New Device(SystemGuid.Keyboard) _device.SetCooperativeLevel(Me, CooperativeLevelFlags.Background Or CooperativeLevelFlags.NonExclusive) _device.SetDataFormat(DeviceDataFormat.Keyboard) 'Add any initialization after the InitializeComponent() call End Sub 'Form overrides dispose to clean up the component list. Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean) If disposing Then If Not (components Is Nothing) Then components.Dispose() End If End If MyBase.Dispose(disposing) End Sub 'Required by the Windows Form Designer Private components As System.ComponentModel.IContainer 'NOTE: The following procedure is required by the Windows Form Designer 'It can be modified using the Windows Form Designer. 'Do not modify it using the code editor. <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent() components = New System.ComponentModel.Container() Me.Text = "Form1" End Sub #End Region End Class [Edited by - chosendl on March 1, 2007 1:34:18 PM]

Share this post


Link to post
Share on other sites
chosendl    122
Hi there thanx for the response, but it doesn't seem to have helped. I put in MyBase.show() directly before the create device.
I edited my original post so that you can see this.

Any other ideas... Anyone?

Share this post


Link to post
Share on other sites
chosendl    122
I am not getting much response here, perhaps people dont like looking through alot of code, so here are just two lines:

_device = New Device(SystemGuid.Keyboard)
_device.SetCooperativeLevel(Me, CooperativeLevelFlags.Background Or CooperativeLevelFlags.NonExclusive)

The set cooperative line generates a directinput.dll exception and i dont know why! Can anyone help?

Share this post


Link to post
Share on other sites
Dave Hunt    4872
Quote:
Original post by chosendl
Hi there thanx for the response, but it doesn't seem to have helped. I put in MyBase.show() directly before the create device.
I edited my original post so that you can see this.

Any other ideas... Anyone?


Well, you called MyBase.Show, but you used Me as the top-level control in your call to SetCooperativeLevel. Try calling Show on your form.

Share this post


Link to post
Share on other sites
chosendl    122
Tried that, still a problem. This problem is occuring with any input device that i try using directinput for. I found a complete direct input keyboard class written in c#, so converted it to vb, and it gave the error message, but the c# version worked!
However, i use vb and have no intention of starting c#, so this is completely useless.
Perhaps somebody could post a small class where they have successfully initialized direct input , so that i can compare it to my own code.

Share this post


Link to post
Share on other sites
perkbrian    122
can you do a try/catch around where the error occurred and get a more detailed error description?

i dont know about VB but C#:

try
{
//code
}
catch (Direct3DXException ex)//or DirectXException
{
MessageBox.Show(ex.Message);
}

Share this post


Link to post
Share on other sites
perkbrian    122
go to the DirectX Control panel (either in the windows Control Panel or in the start menu) and set it to use the Debug version of Direct3D...

also, in the "Managed" tab make sure that the DirectInput version that you are using is set to debug mode also...

if you're using managed (i guess you are) and Visual studio, go to the project properties and check the unmanaged debugging box...

run in debug mode and check the output window...

i would just fiddle around with the CoopLvlFlags you have set and find out if its that

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this