Problem with DirectInput
I have a problem using DirectInput in VisualBasic 6.
Well i use this code:
Dim dx7 as New Directx7
Dim dInput As DirectInput
Dim inpDev As DirectInputDevice
Dim kState As DIKEYBOARDSTATE
Public Sub InitKeyboard()
Set dInput = dx7.DirectInputCreate()
Set inpDev = dInput.CreateDevice("GUID_SysKeyboard")
Call inpDev.SetCommonDataFormat(DIFORMAT_KEYBOARD)
Call inpDev.SetCooperativeLevel(Form1.hwnd, DISCL_BACKGROUND Or DISCL_NONEXCLUSIVE)
Call inpDev.Acquire
Call inpDev.GetDeviceStateKeyboard(kState)
End Sub
- I call this sub from Sub Main()(the code is in a module)
- To get the keys i use a sub called UserInput called in my main game loop(in Sub Main() )
- For example:
Public Sub UserInput()
if state.key(DIK_RIGHT) And &H80 then
''Move Right
End if
- Unfortunately when i press the keys nothing happens.
- If i use the GetKeyState() API function instead everything works fine.
Please tell me what could be wrong with my code or your own way to implement directinput in VB.
Thanks
Voodoo4
I don''t know much about VB since i''m a C++ coder but... I think you''ve just forgotten to put "Call inpDev.Acquire" in your loop.
You must not only acquire devices when you initializes it, but at each frame.
Well in fact i''m not sure at all. I''ve written a DirectInput wraper and so i don''t use it very often. But try it and tell us if it works.
Prosper / LOADED corporation
You must not only acquire devices when you initializes it, but at each frame.
Well in fact i''m not sure at all. I''ve written a DirectInput wraper and so i don''t use it very often. But try it and tell us if it works.
Prosper / LOADED corporation
You only have to aquire when you application gets a WM_ACTIVATE (that is each the your app becomes the active "application" ). Thereby you will "lose" the device when your app is in the background and retrive it when it is brougth to the foreground.
no idea how you do that in visual basic =)
no idea how you do that in visual basic =)
The application is fullscreen so it is meant to be always in the foreground(it is a game).
I am using the API call GetKeyAsyncState to get keystrokes instead of DirectInput and it works fine.But i think you are right Prosper,i should acquire keyboard at each loop.
I''m gonna try it and i''ll tell you if it works.
Thanks
I am using the API call GetKeyAsyncState to get keystrokes instead of DirectInput and it works fine.But i think you are right Prosper,i should acquire keyboard at each loop.
I''m gonna try it and i''ll tell you if it works.
Thanks
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement