forked from vixorien/AdvancedDX11Starter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInput.h
92 lines (70 loc) · 1.67 KB
/
Input.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#pragma once
#include <Windows.h>
class Input
{
#pragma region Singleton
public:
// Gets the one and only instance of this class
static Input& GetInstance()
{
if (!instance)
{
instance = new Input();
}
return *instance;
}
// Remove these functions (C++ 11 version)
Input(Input const&) = delete;
void operator=(Input const&) = delete;
private:
static Input* instance;
Input() {};
#pragma endregion
public:
~Input();
void Initialize(HWND windowHandle);
void Update();
void EndOfFrame();
int GetMouseX();
int GetMouseY();
int GetMouseXDelta();
int GetMouseYDelta();
float GetMouseWheel();
void SetWheelDelta(float delta);
bool KeyDown(int key);
bool KeyUp(int key);
bool KeyPress(int key);
bool KeyRelease(int key);
bool GetKeyArray(bool* keyArray, int size = 256);
bool MouseLeftDown();
bool MouseRightDown();
bool MouseMiddleDown();
bool MouseLeftUp();
bool MouseRightUp();
bool MouseMiddleUp();
bool MouseLeftPress();
bool MouseLeftRelease();
bool MouseRightPress();
bool MouseRightRelease();
bool MouseMiddlePress();
bool MouseMiddleRelease();
void SetGuiKeyboardCapture(bool capture) { guiWantsKeyboard = capture; }
void SetGuiMouseCapture(bool capture) { guiWantsMouse = capture; }
private:
// Arrays for the current and previous key states
unsigned char* kbState {0};
unsigned char* prevKbState {0};
// Mouse position and wheel data
int mouseX {0};
int mouseY {0};
int prevMouseX {0};
int prevMouseY {0};
int mouseXDelta {0};
int mouseYDelta {0};
float wheelDelta {0};
bool guiWantsKeyboard;
bool guiWantsMouse;
// The window's handle (id) from the OS, so
// we can get the cursor's position
HWND windowHandle {0};
};