/*
* InputSystem.h
* Jonathan Boldiga
* 09/02/03
*
* Description: This class handles all input devices and implements direct input,
* handles mouse, keyboard, and joystick input.
*
*/
#ifndef __INPUTCONTROLSYSTEM_H__
#define __INPUTCONTROLSYSTEM_H__
#include
#define IS_USEKEYBOARD 1
#define IS_USEMOUSE 2
#define IS_USEJOYSTICK 4
class Keyboard{
public:
Keyboard(LPDIRECTINPUT8 directInput, HWND hwnd);
~Keyboard();
bool KeyDown(char key) { return (m_keys[key] & 0x80) ? true : false; }
bool KeyUp(char key) { return (m_keys[key] & 0x80) ? false : true; }
bool Update();
void Clear() { ZeroMemory(m_keys, 256 * sizeof(char)); }
bool Acquire();
bool UnAcquire();
private:
LPDIRECTINPUTDEVICE8 directInputDevice;
char m_keys[256];
};
class Mouse{
public:
Mouse(LPDIRECTINPUT8 directInput, HWND hwnd, bool isExclusive = true);
~Mouse();
bool ButtonDown(int button) { return (m_state.rgbButtons[button] & 0x80) ? true : false; }
bool ButtonUp(int button) { return (m_state.rgbButtons[button] & 0x80) ? false : true; }
void GetMovement(int &dx, int &dy) { dx = m_state.lX; dy = m_state.lY; }
bool Update();
bool Acquire();
bool UnAcquire();
private:
LPDIRECTINPUTDEVICE8 directInputDevice;
DIMOUSESTATE m_state;
};
class Joystick{
public:
Joystick(LPDIRECTINPUT8 directInput, HINSTANCE appInstance);
~Joystick();
bool Update();
bool Acquire();
bool UnAcquire();
private:
LPDIRECTINPUTDEVICE8 directInputDevice;
};
class InputSystem{
public:
InputSystem() { keyboard = NULL; mouse = NULL; joystick = NULL; }
~InputSystem() {}
bool Initialize(HWND hwnd, HINSTANCE appInstance, bool isExclusive, DWORD flags = 0);
bool Shutdown();
void AcquireAll();
void UnAcquireAll();
Keyboard* getKeyboard() { return keyboard; }
Mouse* getMouse() { return mouse; }
Joystick* getJoystick() { return joystick; }
bool Update();
bool KeyDown(char key) { return (keyboard && keyboard->KeyDown(key)); }
bool KeyUp(char key) { return (keyboard && keyboard->KeyUp(key)); }
bool ButtonDown(int button) { return (mouse && mouse->ButtonDown(button)); }
bool ButtonUp(int button) { return (mouse && mouse->ButtonUp(button)); }
void GetMouseMovement(int &dx, int &dy) { if (mouse) mouse->GetMovement(dx, dy); }
private:
Keyboard* keyboard;
Mouse* mouse;
Joystick* joystick;
LPDIRECTINPUT8 m_pDI;
};
#endif