Archived

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

JoHnOnIzEr

Direct Input ;x

Recommended Posts

JoHnOnIzEr    146
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]

Share this post


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

Share this post


Link to post
Share on other sites
JoHnOnIzEr    146
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?

Share this post


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

Share this post


Link to post
Share on other sites