directinput keyboard ?

Started by
7 comments, last by perkbrian 17 years, 1 month ago
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]
Advertisement
Try calling Show() on the form before setting up the device. I seem to recall having a similar problem some time ago.
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?
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?
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.
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.
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);}
error message = "Error in the application"
error string = "E_Handle" (whatever that means!)
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

This topic is closed to new replies.

Advertisement