




| Managing input hardware in game with DirectInput |
|
|
|
| Written by Zamrony P. Juhara | |||||
| Thursday, 07 January 2010 13:34 | |||||
Page 1 of 3 Article on how to utilize DirectInput to control player character in game. This article explains you how to take advantages of input control such as keyboard, mouse and joystick in game application. What and Why DirectInput?DirectInput is one of component of DirectX. Its main purpose is to wrap accessing input hardware (mouse, keyboard, joystick etc) into a uniform interface for diverse input hardwares. There are so many input hardware vendor and how to access their input hardware may different for each device. If you're back to DOS age, developing game was much more exhaustive. A game should support as much hardware as possible. It means game developer should develop their own code for accesing hardware device for every hardware avalable on the market. DirectX, especially DirectInput, solves this problem by using thin layer called Hardware Abstraction Layer (HAL). For a input device can be used in Windows operating system, its vendor must implement HAL. Game applications do not access hardware device directly anymore, but through DirectInput. DirectInput communicates with device driver through HAL and finally device driver talks with hardware. Because DirectInput communicates directly to hardware driver (via HAL), DirectInput bypasses Windows messaging system. Therefore, if we use DirectInput for accessing keyboard, messages such as WM_KEYDOWN or WM_KEYUP will not be sent to our application. Games (for example fighting genre games) usually use combination of some keys instruct player character in game to do something for example fiercing. It forces players to push arrow down and Enter key simultaneously. Such combination cannot be detected if we use WM_KEYDOWN message. Combinations that can be detected with WM_KEYDOWN are only combination of Shift. Alt, and Ctrl with other keys. Other problem is delay between time when a key is pressed and time when it becomes key repetition. If you press a key for example A, A will be print and then there will be delay for about half second (depends on your system configuration) before key pressed produce AAAAAAA......on the screen. For games, this delay is not wanted. Games typcally wants more responsive output. If player presses right arrow, player expects character in game will move to the right as soon as possible and keep moving until key is released. DOS game programmer used to intercept interrupt 09h to address this issue. Fortunately, with DirectInput we don't need to deal with interrupt. Ok let's get it on.. |
|||||
| Last Updated on Thursday, 07 January 2010 13:56 |