Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Voodoo4

Problem with DirectInput

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
Advertisement
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

Share this post


Link to post
Share on other sites
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 =)

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
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

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!