Direct Input ;x

Started by
3 comments, last by JoHnOnIzEr 20 years, 8 months ago
Im using vb, and when i use the arrow keys when im using a different program other than my game the game thinks im telling it to move even tho i dont want it to. I know im doing osmething wrong but i dont know what. ;x Decalres

'DirectX Stuff
'
Public dX As New DirectX7 'Direct X Object
Public DDRAW As DirectDraw7 'DirectDraw
Public DI As DirectInput 'Direct Input
Public DS As DirectSound
Public ColorKey As DDCOLORKEY

'Direct Input
Public DIKEYBOARD As DirectInputDevice
Public KeyState As DIKEYBOARDSTATE
 
Initialize

'Direct Input
'
Set DI = dX.DirectInputCreate()
Set DIKEYBOARD = DI.CreateDevice("GUID_SysKeyboard") 'Create a keyboard object off the Input object
DIKEYBOARD.SetCommonDataFormat DIFORMAT_KEYBOARD 'specify it as a normal keyboard, not mouse or joystick
DIKEYBOARD.SetCooperativeLevel frmHwnd, DISCL_BACKGROUND Or DISCL_NONEXCLUSIVE
DIKEYBOARD.Acquire   'aquire the keystates.
 
I hope this helps :/ [edited by - JoHnOnIzEr on August 8, 2003 11:05:47 PM]
Sidra Headquarters
Game engine is currently at version 0.9.8! Currently Down
Advertisement
quote:Original post by JoHnOnIzEr
Im using vb, and when i use the arrow keys when im using a different program other than my game the game thinks im telling it to move even tho i dont want it to.



DIKEYBOARD.SetCooperativeLevel frmHwnd, DISCL_BACKGROUND Or DISCL_NONEXCLUSIVE


Although I''ve never used VB before, I think that this is where your problem is. You setup your keyboard to have background access. This basically means that your app will respond to the keyboard reguardless of whether it''s in the foreground or background. Usually, most apps only want to respond to input when they''re in the foreground. So just change DISCL_BACKGROUND to DISCL_FOREGROUND and everything should be ok.

Hope this helps,
neneboricua

When I click off my game now i get an automation error because now it cant get the keystates since its in foreground. So now my question is, would you happen to know how to tell if my program is the one currently being used?
Sidra Headquarters
Game engine is currently at version 0.9.8! Currently Down
quote:Original post by JoHnOnIzEr
When I click off my game now i get an automation error because now it cant get the keystates since its in foreground. So now my question is, would you happen to know how to tell if my program is the one currently being used?


I don''t think you need to go through all that trouble, at least not for this kind of thing. I hope I haven''t missunderstood your question.

Make sure you call "Acquire" on your devece before you try to get the keyboard''s state. Redundant "Acquire" calls are ignored by the device so it''s ok. Then call the "GetDeviceState" function (not sure what it''s called in VB but this is the name in C++) to get the state of the keyboard. If this call succeeds, then go ahead and process your input like you normall would. But if it fails, that tells you that the data you just got from the keyboard is garbage. In that case, just return from your input processing function and just render the scene as if the user hadn''t pressed any keys at all.

See if that works,
neneboricua
Thanks. It works .
Sidra Headquarters
Game engine is currently at version 0.9.8! Currently Down

This topic is closed to new replies.

Advertisement