how to get input from various keyboards with directinput
First sorry for my bad english...
I want to get input from various USB keyboard, and I need to know from which keyboard I get the keystroke, I prove the directinput objects in VB 2005. This are the code that I use in the declaration section (in this case I use 2 USB Keyboard)
Implements DirectXEvent8
Private MiDirectXAsNew DirectX8
Private MiDirectInputAs DirectInput8'the object to my first keyboardPrivate diDevAs DirectInputDevice8
'the object to my second keyboard
Private diDev2As DirectInputDevice8
'Private keyStateAs DIKEYBOARDSTATE
Private keyState2As DIKEYBOARDSTATE
Private ManejaEventoAsLongPrivate ManejaEvento2AsLong-
To get the GUID for my keyboards I use the next code
Dim
diDevEnumAs DirectInputEnumDevices8diDevEnum = MiDirectInput.GetDIDevices(CONST_DI8DEVICETYPE.DI8DEVCLASS_DEVICE, CONST_DIENUMDEVICESFLAGS.DIEDFL_ALLDEVICES)
For i = 1To diDevEnum.GetCount
Debug.Print(diDevEnum.GetItem(i).GetGuidInstance)
Next iThen I get the GUID for all keyboards that I have connected to my PC.
The code return string like that for all keyboard that are connected to PC
{A3AA2DD0-18C3-11DB-8001-444553540000}
{A3AC9ED0-18C3-11DB-8003-444553540000}
--
In the form load secction I use the next code
PrivateSub Prueba_Load(ByVal senderAs System.Object,ByVal eAs System.EventArgs)HandlesMyBase.LoadMiDirectInput = MiDirectX.DirectInputCreate()
'for the keyboard ONE I use the GUID string that I get usingdiDev = MiDirectInput.CreateDevice(
"{A3AA2DD0-18C3-11DB-8001-444553540000}")'diDev = MiDirectInput.CreateDevice("GUID_SYSKeyboard")
' I'm not use the string "GUID_SYSKeyboard" to create a keyboard device, because the code don't diference from a keyboard from others, else this interpret the input from various keyboard like if I have only one
diDev.SetCommonDataFormat(CONST_DICOMMONDATAFORMATS.DIFORMAT_KEYBOARD)
diDev.SetCooperativeLevel(
Me.Handle, CONST_DISCLFLAGS.DISCL_NONEXCLUSIVEOr CONST_DISCLFLAGS.DISCL_BACKGROUND)'this print that I have a USB_Keyboard device
Debug.Print(diDev.GetDeviceInfo().GetInstanceName())
ManejaEvento = MiDirectX.CreateEvent(
Me)diDev.SetEventNotification(ManejaEvento)
diDev.Acquire()
'for my keyboard 2 I use the next codediDev2 = MiDirectInput.CreateDevice("{A3AC9ED0-18C3-11DB-8003-444553540000}")
diDev2.SetCommonDataFormat(CONST_DICOMMONDATAFORMATS.DIFORMAT_KEYBOARD)
diDev2.SetCooperativeLevel(
Me.Handle, CONST_DISCLFLAGS.DISCL_NONEXCLUSIVEOr CONST_DISCLFLAGS.DISCL_BACKGROUND)'this print that I have a USB_Keyboard device
Debug.Print(diDev2.GetDeviceInfo().GetInstanceName())
ManejaEvento2 = MiDirectX.CreateEvent(
Me)diDev2.SetEventNotification(ManejaEvento2)
diDev2.Acquire()
End Sub-
Now I use aDXCallback event, but it doesn't found..
Public
Sub DXCallback(ByVal eventidAsInteger)Implements DxVBLibA.DirectXEvent8.DXCallbackIf eventid = ManejaEventoThenCall diDev.GetDeviceStateKeyboard(keyState)'the function Teclas return a key name
TextBox1.Text = TextBox1.Text & Teclas(keyState)
EndIfIf eventid = ManejaEvento2ThenCall diDev2.GetDeviceStateKeyboard(keyState2)TextBox2.Text = TextBox2.Text & Teclas(keyState2)
EndIfEndSubSomeone can tell me what I do wrong?

