# directinput keyboard ?

This topic is 4095 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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 on other sites
Try calling Show() on the form before setting up the device. I seem to recall having a similar problem some time ago.

##### Share on other sites
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 on other sites
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 on other sites
Quote:
 Original post by chosendlHi 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 on other sites
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 on other sites
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 on other sites
error message = "Error in the application"
error string = "E_Handle" (whatever that means!)

##### Share on other sites
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

• 12
• 9
• 13
• 41
• 15