-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinput.h
More file actions
64 lines (45 loc) · 1.37 KB
/
input.h
File metadata and controls
64 lines (45 loc) · 1.37 KB
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
#pragma once
#include <windows.h>
#include <stdint.h>
#include "keyCodes.h"
#include <windowsx.h>
#define DC_MAX_KEYS 53
#define DC_MAX_MOUSE_BUTTONS 5
namespace gameApp {
class Input {
friend LRESULT CALLBACK WindowCallback(HWND windowHandle, UINT message, WPARAM wParam, LPARAM lParam);
public:
struct KeyState {
bool wasDown, isDown;
};
struct KeyBoardInputMap {
KeyState keys[DC_MAX_KEYS];
};
struct ButtonState {
bool wasDown, isDown;
};
struct Position{
int x, y;
};
struct MouseInputMap {
ButtonState buttons[DC_MAX_MOUSE_BUTTONS];
Position position;
};
static KeyState GetKeyState(uint32_t keycode);
static bool isKeyPressed(uint32_t keycode);
static bool isKeyReleased(uint32_t keycode);
//returns true if key has just been pressed
static bool wasKeyHit(uint32_t keycode);
static Position getMousePosition();
static bool isMouseButtonPressed(unsigned int buttonCode);
static bool isMouseButtonReleased(unsigned int buttonCode);
//returns true if mouse button has just been pressed
static bool wasMouseButtonHit(unsigned int buttonCode);
private:
static void processKeyboardInput(uint32_t keycode, bool wasDown, bool isDown);
static KeyBoardInputMap keyboard;
static MouseInputMap mouse;
static void processMouseInput(WPARAM wParam, LPARAM lParam);
static void updateMousePosition(LPARAM lParam);
};
}