-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinput.h
More file actions
46 lines (28 loc) · 957 Bytes
/
input.h
File metadata and controls
46 lines (28 loc) · 957 Bytes
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
#pragma once
#include <SDL2/SDL.h>
#include <cstring>
class Input {
public:
static void Init() {
keyboardState = SDL_GetKeyboardState(nullptr);
memset(prevKeyboardState, 0, sizeof(prevKeyboardState));
}
static void Update() {
memcpy(prevKeyboardState, keyboardState, SDL_NUM_SCANCODES);
SDL_PumpEvents();
}
static bool IsDown(SDL_Scancode key) {
return keyboardState[key];
}
static bool IsPressed(SDL_Scancode key) {
return keyboardState[key] && !prevKeyboardState[key];
}
static bool IsReleased(SDL_Scancode key) {
return !keyboardState[key] && prevKeyboardState[key];
}
private:
static const Uint8* keyboardState;
static Uint8 prevKeyboardState[SDL_NUM_SCANCODES];
};
const Uint8* Input::keyboardState = nullptr;
Uint8 Input::prevKeyboardState[SDL_NUM_SCANCODES];