views:

1114

answers:

5

What is the prefered way of handling keyboard input in programs like games? Is directX input the easiest choice? What are the other options?

+1  A: 

DirectInput (if that's what you mean by directX input) has been deprecated. I, personally, find it sufficient to handle the messages sent to the WndProc of your main window. See WMINPUT, or WMKEYDOWN and WMKEYUP

EDIT: I was assuming you're making a game using Directx. If you're not, it really depends on how you're making your game to choose input. If you're using a cross-platform existing library it will have a way of handling input that's built in.

A: 

It mostly depends on what framework/OS you intend to use for your game.

Options are too numerous to all list here, but include :

  • XNA (Windows + XBox 360)
  • DirectX (Windows)
  • Flash (Cross-Platform)
  • Silverlight (Should be cross-platform)

Various integrated game engines :

  • Torque
  • Dark gdk
  • ...

Cross-Platform libraries

  • Allegro
  • LWJGL
  • ...

Frankly, it's highly unprobable than handling input is going to be your biggest problem, so pick a solution that fits your need (in particular in terms of grahic capability/complexity) and choose your way of handling input from there.

Axelle Ziegler
A: 

Nothing wrong with DirectInput. Works well and gives you direct access to the hardware via a ... er... "friendly" interface :) Polling the hardware is the only way to go if you want real responsiveness in your game.

Relying on the Windows message pump and handling windows messages is, imho, an EPIC FAIL.

OJ
A: 

Typically you choose the input handling method that best fits your windowing system. If you're using GLUT/SDL/SFML or any of the other windowing toolkits you'll get your input from them. Otherwise if you're rolling your own then it's between using the OS input messages or DirectInput, both of which work swimmingly for games.

If you're thinking about mouse input, do NOT use DirectInput unless you have very specific mouse ballistics you intend to apply. DirectInput mouse motion does not have the user's mouse ballisitics applied to it (set via the mouse control panel) and will feel very awkward for most users.

Ron Warholic
+1  A: 

All DirectInput is doing for keyboard input is creating a thread and watching the WM_* messages and adding overhead of the extra thread. Even Microsoft says you should just the WM_* messages. I see some EPIC FAIL, but not on the part of the windows message queue.