📄 cdirectinput.h
字号:
/*
Class Name:
CDirectInputSystem, CInputKeyboard, CInputMouse.
Created by:
Allen Sherrod (Programming Ace of www.UltimateGameProgramming.com).
Description:
These classes are used with DirectInput to get input from a keyboard and/or mouse.
*/
#ifndef CDIRECTINPUT_H
#define CDIRECTINPUT_H
#define LEFT_BUTTON 0 // Reps the left mouse button.
#define RIGHT_BUTTON 1 // Reps the right mouse button.
#define KEYS_SIZE 256 // Total number of keys.
#include<dinput.h> // Direct Input header file.
// Prototypes...
class CInputKeyboard;
class CInputMouse;
// Input system class.
class CDirectInputSystem
{
public:
CDirectInputSystem(); // Constructor.
~CDirectInputSystem(); // Destructor.
public:
// Initialize our input system and all supported devices.
bool Initialize(HWND hwnd, HINSTANCE hInstance, bool mouseExclusive = false);
bool AcquireDevices(); // Gain acces to all devices.
bool UnAcquireDevices(); // Take away access.
bool UpdateDevices(); // Update the states of the devices.
bool KeyUp(int key); // Check if a key is not pressed.
bool KeyDown(int key); // Check if a key is pressed.
bool MouseButtonUp(int button); // Check if a mouse button is not pressed.
bool MouseButtonDown(int button); // Check if a mouse button is pressed.
bool Shutdown(); // Shutdown the input system.
protected:
LPDIRECTINPUT8 m_InputSystem; // Direct Input device object.
CInputKeyboard *m_Keyboard; // Hold our keyboard device.
CInputMouse *m_Mouse; // Hold our mouse device.
};
// Keyboard class.
class CInputKeyboard
{
public:
CInputKeyboard(); // Constructor.
~CInputKeyboard(); // Destructor.
public:
bool Initialize(LPDIRECTINPUT8 m_InputSystem, HWND hwnd); // Initialize the keyboard.
bool KeyUp(int key); // Check if a key is not pressed.
bool KeyDown(int key); // Check if a key is pressed.
bool AcquireDevice(); // Gain access to keyboard.
bool UnAcquireDevice(); // Take access away.
bool UpdateDevice(); // Update device by getting which keys are pressed.
void ClearKeys(); // Clear the m_Keys array.
bool Shutdown(); // Shut down this device.
protected:
LPDIRECTINPUTDEVICE8 m_Keyboard; // Direct Input device representing the keyboard.
char m_Keys[KEYS_SIZE]; // All the keys on a keyboard.
};
// Mouse class.
class CInputMouse
{
public:
CInputMouse(); // Constructor.
~CInputMouse(); // Destructor.
public:
// Initialize mouse input device.
bool Initialize(LPDIRECTINPUT8 m_InputSystem, HWND hwnd, bool isExclusive = false);
bool ButtonUp(int button); // Test if a button is not pressed.
bool ButtonDown(int button); // Test if a button is pressed.
bool AcquireDevice(); // Gain access to our mouse device.
bool UnAcquireDevice(); // Take away access to the device.
bool UpdateDevice(); // Update the device and get the device states.
bool Shutdown(); // Shutdown the mouse input device.
protected:
LPDIRECTINPUTDEVICE8 m_Mouse; // Direct Input device representing the mouse.
DIMOUSESTATE m_Mouse_State; // Object to hold the state of the mouse.
};
#endif
// Copyright March 2003
// All Rights Reserved!
// Allen Sherrod
// ProgrammingAce@UltimateGameProgramming.com
// www.UltimateGameProgramming.com
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -