Sign in to follow this  
Fallen_Angel

Advantages of DirectInput over OnKeyDown/OnKeyUp - (slight DirectInput problem now)

Recommended Posts

At the moment the OnKeyDown/OnKeyUp functionality looks a lot more straight forward and I already have code in this format that I can re-use. I'm just curious if there are any real advantages to using DirectInput instead and if it is worthwhile converting my code? Thanks [Edited by - Fallen_Angel on December 2, 2004 1:40:28 AM]

Share this post


Link to post
Share on other sites
I haven't been working with DI very much, but by experience I would say it would be easier to get it running (on a fullscale application) as it has better overall functionality and support in general and for other devices as if you would like to use non-keyboard input etc in the future.

In my opinion, stick to whatever suits you, if you are planing a "greater" application, consider converting to DI... it is rather common that smaller games use the Windows API instead/other APIs.

Share this post


Link to post
Share on other sites
Myself, I've found that using the OnKeyDown/OnKeyUp events don't provide as responsive input. DirectInput is much more responsive to the player and seems to update its internal state more often. DirectInput isn't very hard to learn, plus you can use non-keyboard devices if you really want to.

Share this post


Link to post
Share on other sites
i think the advantage of directinput is that it doesn't wait for the windows message queue to get around to processing the onkeyup/down message.

i could be talking out of my ass though, i only started learning directx for a few weeks

Share this post


Link to post
Share on other sites
If you listen for WM_KEY messages, it's very responsive. If you wait for WM_CHAR, it may take longer, but only very slightly. Neither should be less responsive than DirectInput.

The reason to use DirectInput is to get support for game pads, steering wheels, joysticks, and other such devices. There just isn't a good way to read them any other way, and not supporting them often detracts from a game (depending on the game, of course).

Share this post


Link to post
Share on other sites
Thanks for the input everyone. I've gone and looked into DirectInput now seeing as I will end up using the mouse later on and it's not as bad as I thought. I am however having one problem. This is when I try to check the state of custom input keys. I have gotten my input to work as follows:

KeyboardState state = deviceKeyboard.GetCurrentKeyboardState();
if (state[Key.Up])
{
//do stuff
}


What I wold like to be able to do is:

KeyboardState state = deviceKeyboard.GetCurrentKeyboardState();
if ((state[Key.Up]) || (state[strCustomUp]))
{
//do stuff
}


Can anyone point me in the right direction here?

Thanks

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this