Building the Right Environment to Support AI, Machine Learning and Deep Learning
Environment: Win9x, Windows NT/2000, DirectX Installed
IntroductionDirectInput is essential for responsive games, therefore to help ease the transition of DOS games programmers, you can use this class to read the keyboard direct trapping input before Windows starts performing it translation functions.
To use the class, define a global variable :-
The class has the following public methods:-
CDIKeyboard.SetHWND(HWND)Set the windows handle to which Direct Input Will be attached to. Must be the Parent Window.
Set the windows handle to which Direct Input Will be attached to. Must be the Parent Window. MFC Version.
CDIKeyboard mkbrd; mkbrd.SetHWND(this);
Obtain and update the keyboard state information.
bool CDIKeyboard.IsKeyPressed(unsigned char)
returns true if a DIK_KEY is pressed, false if not. Example:
bool CDIKeyboard.Acquire(bool state)
Acquire/Unacquire the Keyboard Device. You will need to Unacquire the device if you want Windows to handle WM_CHAR, WM_KEYUP, WM_KEYDOWN messages.
state=true To Acquire
state=false To UnAcquire
Returns : true=Operation Successful, false=Operation unsuccessful
Before obtaining keyboard state information you will need to set the HWND of the parent window of your application. Use PollDevice method before checking the Keyboard state information and IsKeyPressed(key) method to check a particular key has been pressed.
The following code snippet can be used to show which keys have been pressed
bool m_bInput; myKeyboard.PollDevice(); m_bInput=myKeyboard.IsKeyPressed(DIK_F1)?true:false;
DownloadsDownload base source project - 4 Kb
Download source - 2 Kb