P-E-R-R-Y
Utilitaires, contrats et vendors du moteur, en une seule doc
Loading...
Searching...
No Matches
SdlKeyboard.hpp
Go to the documentation of this file.
1
10
11#ifndef SDLKEYBOARD_HPP_
12#define SDLKEYBOARD_HPP_
13
14//Sdl
15#include <SDL3/SDL.h>
16
17//Interface
18#include "IKeyboard.hpp"
19
20#include <unordered_map>
21#include <vector>
22
23class SdlWindow;
24
33class SdlKeyboard : public graphic::IKeyboard {
34
35 public:
36 SdlKeyboard(const SdlWindow &window) : _window(window) {}
37 ~SdlKeyboard() override = default;
38
39 //definis dans SdlWindow.hpp, une fois SdlWindow complete
40 std::vector<Keys> whichKeyDown() const override;
41 bool isKeyPressed(Keys key) const override;
42 bool isKeyReleased(Keys key) const override;
43 bool isKeyDown(Keys key) const override;
44 bool isKeyUp(Keys key) const override;
45
46 private:
47 const SdlWindow &_window;
48
49 const std::unordered_map<graphic::IKeyboard::Keys, SDL_Scancode> _keys = {
50 //line 0
51 {graphic::IKeyboard::Keys::KEY_ESCAPE, SDL_SCANCODE_ESCAPE},
52 {graphic::IKeyboard::Keys::KEY_F1, SDL_SCANCODE_F1},
53 {graphic::IKeyboard::Keys::KEY_F2, SDL_SCANCODE_F2},
54 {graphic::IKeyboard::Keys::KEY_F3, SDL_SCANCODE_F3},
55 {graphic::IKeyboard::Keys::KEY_F4, SDL_SCANCODE_F4},
56 {graphic::IKeyboard::Keys::KEY_F5, SDL_SCANCODE_F5},
57 {graphic::IKeyboard::Keys::KEY_F6, SDL_SCANCODE_F6},
58 {graphic::IKeyboard::Keys::KEY_F7, SDL_SCANCODE_F7},
59 {graphic::IKeyboard::Keys::KEY_F8, SDL_SCANCODE_F8},
60 {graphic::IKeyboard::Keys::KEY_F9, SDL_SCANCODE_F9},
61 {graphic::IKeyboard::Keys::KEY_F10, SDL_SCANCODE_F10},
62 {graphic::IKeyboard::Keys::KEY_F11, SDL_SCANCODE_F11},
63 {graphic::IKeyboard::Keys::KEY_F12, SDL_SCANCODE_F12},
64 //line 1
65 {graphic::IKeyboard::Keys::KEY_1, SDL_SCANCODE_1},
66 {graphic::IKeyboard::Keys::KEY_2, SDL_SCANCODE_2},
67 {graphic::IKeyboard::Keys::KEY_3, SDL_SCANCODE_3},
68 {graphic::IKeyboard::Keys::KEY_4, SDL_SCANCODE_4},
69 {graphic::IKeyboard::Keys::KEY_5, SDL_SCANCODE_5},
70 {graphic::IKeyboard::Keys::KEY_6, SDL_SCANCODE_6},
71 {graphic::IKeyboard::Keys::KEY_7, SDL_SCANCODE_7},
72 {graphic::IKeyboard::Keys::KEY_8, SDL_SCANCODE_8},
73 {graphic::IKeyboard::Keys::KEY_9, SDL_SCANCODE_9},
74 {graphic::IKeyboard::Keys::KEY_0, SDL_SCANCODE_0},
75 {graphic::IKeyboard::Keys::KEY_MINUS, SDL_SCANCODE_MINUS},
76 {graphic::IKeyboard::Keys::KEY_EQUAL, SDL_SCANCODE_EQUALS},
77 {graphic::IKeyboard::Keys::KEY_BACKSPACE, SDL_SCANCODE_BACKSPACE},
78 //line 2
79 {graphic::IKeyboard::Keys::KEY_TAB, SDL_SCANCODE_TAB},
80 {graphic::IKeyboard::Keys::KEY_Q, SDL_SCANCODE_Q},
81 {graphic::IKeyboard::Keys::KEY_W, SDL_SCANCODE_W},
82 {graphic::IKeyboard::Keys::KEY_E, SDL_SCANCODE_E},
83 {graphic::IKeyboard::Keys::KEY_R, SDL_SCANCODE_R},
84 {graphic::IKeyboard::Keys::KEY_T, SDL_SCANCODE_T},
85 {graphic::IKeyboard::Keys::KEY_Y, SDL_SCANCODE_Y},
86 {graphic::IKeyboard::Keys::KEY_U, SDL_SCANCODE_U},
87 {graphic::IKeyboard::Keys::KEY_I, SDL_SCANCODE_I},
88 {graphic::IKeyboard::Keys::KEY_O, SDL_SCANCODE_O},
89 {graphic::IKeyboard::Keys::KEY_P, SDL_SCANCODE_P},
90 {graphic::IKeyboard::Keys::KEY_LEFT_BRACKET, SDL_SCANCODE_LEFTBRACKET},
91 {graphic::IKeyboard::Keys::KEY_RIGHT_BRACKET, SDL_SCANCODE_RIGHTBRACKET},
92 //line 3
93 {graphic::IKeyboard::Keys::KEY_CAPS_LOCK, SDL_SCANCODE_CAPSLOCK},
95 {graphic::IKeyboard::Keys::KEY_A, SDL_SCANCODE_A},
96 {graphic::IKeyboard::Keys::KEY_S, SDL_SCANCODE_S},
97 {graphic::IKeyboard::Keys::KEY_D, SDL_SCANCODE_D},
98 {graphic::IKeyboard::Keys::KEY_F, SDL_SCANCODE_F},
99 {graphic::IKeyboard::Keys::KEY_G, SDL_SCANCODE_G},
100 {graphic::IKeyboard::Keys::KEY_H, SDL_SCANCODE_H},
101 {graphic::IKeyboard::Keys::KEY_J, SDL_SCANCODE_J},
102 {graphic::IKeyboard::Keys::KEY_K, SDL_SCANCODE_K},
103 {graphic::IKeyboard::Keys::KEY_L, SDL_SCANCODE_L},
104 {graphic::IKeyboard::Keys::KEY_SEMICOLON, SDL_SCANCODE_SEMICOLON},
105 {graphic::IKeyboard::Keys::KEY_APOSTROPHE, SDL_SCANCODE_APOSTROPHE},
106 {graphic::IKeyboard::Keys::KEY_BACKTICK, SDL_SCANCODE_GRAVE},
107 {graphic::IKeyboard::Keys::KEY_ENTER, SDL_SCANCODE_RETURN},
108 //line 4
109 {graphic::IKeyboard::Keys::KEY_LEFT_SHIFT, SDL_SCANCODE_LSHIFT},
110 {graphic::IKeyboard::Keys::KEY_BACKSLASH, SDL_SCANCODE_BACKSLASH},
111 {graphic::IKeyboard::Keys::KEY_Z, SDL_SCANCODE_Z},
112 {graphic::IKeyboard::Keys::KEY_X, SDL_SCANCODE_X},
113 {graphic::IKeyboard::Keys::KEY_C, SDL_SCANCODE_C},
114 {graphic::IKeyboard::Keys::KEY_V, SDL_SCANCODE_V},
115 {graphic::IKeyboard::Keys::KEY_B, SDL_SCANCODE_B},
116 {graphic::IKeyboard::Keys::KEY_N, SDL_SCANCODE_N},
117 {graphic::IKeyboard::Keys::KEY_M, SDL_SCANCODE_M},
118 {graphic::IKeyboard::Keys::KEY_COMMA, SDL_SCANCODE_COMMA},
119 {graphic::IKeyboard::Keys::KEY_PERIOD, SDL_SCANCODE_PERIOD},
120 {graphic::IKeyboard::Keys::KEY_SLASH, SDL_SCANCODE_SLASH},
121 {graphic::IKeyboard::Keys::KEY_RIGHT_SHIFT, SDL_SCANCODE_RSHIFT},
122 //line 5
123 {graphic::IKeyboard::Keys::KEY_LEFT_ALT, SDL_SCANCODE_LALT},
124 {graphic::IKeyboard::Keys::KEY_LEFT_SUPER, SDL_SCANCODE_LGUI},
125 {graphic::IKeyboard::Keys::KEY_SPACE, SDL_SCANCODE_SPACE},
126 {graphic::IKeyboard::Keys::KEY_RIGHT_ALT, SDL_SCANCODE_RALT},
129 //keypad
130 {graphic::IKeyboard::Keys::KEY_PAD_0, SDL_SCANCODE_KP_0},
131 {graphic::IKeyboard::Keys::KEY_PAD_1, SDL_SCANCODE_KP_1},
132 {graphic::IKeyboard::Keys::KEY_PAD_2, SDL_SCANCODE_KP_2},
133 {graphic::IKeyboard::Keys::KEY_PAD_3, SDL_SCANCODE_KP_3},
134 {graphic::IKeyboard::Keys::KEY_PAD_4, SDL_SCANCODE_KP_4},
135 {graphic::IKeyboard::Keys::KEY_PAD_5, SDL_SCANCODE_KP_5},
136 {graphic::IKeyboard::Keys::KEY_PAD_6, SDL_SCANCODE_KP_6},
137 {graphic::IKeyboard::Keys::KEY_PAD_7, SDL_SCANCODE_KP_7},
138 {graphic::IKeyboard::Keys::KEY_PAD_8, SDL_SCANCODE_KP_8},
139 {graphic::IKeyboard::Keys::KEY_PAD_9, SDL_SCANCODE_KP_9},
140 {graphic::IKeyboard::Keys::KEY_PAD_MINUS, SDL_SCANCODE_KP_MINUS},
141 {graphic::IKeyboard::Keys::KEY_PAD_PLUS, SDL_SCANCODE_KP_PLUS},
142 {graphic::IKeyboard::Keys::KEY_PAD_DOT, SDL_SCANCODE_KP_PERIOD},
143 {graphic::IKeyboard::Keys::KEY_PAD_ENTER, SDL_SCANCODE_KP_ENTER},
144 //arrows
145 {graphic::IKeyboard::Keys::KEY_UP, SDL_SCANCODE_UP},
146 {graphic::IKeyboard::Keys::KEY_DOWN, SDL_SCANCODE_DOWN},
147 {graphic::IKeyboard::Keys::KEY_LEFT, SDL_SCANCODE_LEFT},
148 {graphic::IKeyboard::Keys::KEY_RIGHT, SDL_SCANCODE_RIGHT},
149 };
150};
151
153
154#endif /* !SDLKEYBOARD_HPP_ */
Le clavier d'UNE fenetre.
Definition SdlKeyboard.hpp:33
SdlKeyboard(const SdlWindow &window)
Definition SdlKeyboard.hpp:36
bool isKeyPressed(Keys key) const override
Check if the key is pressed.
std::vector< Keys > whichKeyDown() const override
Every key HELD right now - like isKeyDown, without having to name the key.
bool isKeyDown(Keys key) const override
Check if the key is down.
bool isKeyUp(Keys key) const override
Check if the key is up.
bool isKeyReleased(Keys key) const override
Check if the key is released.
~SdlKeyboard() override=default
Une fenetre SDL et son renderer, implemente IWindow2.
Definition SdlWindow.hpp:50
Keyboard interface.
Definition IKeyboard.hpp:78
Keys
Scan codes.
Definition IKeyboard.hpp:86
@ KEY_F3
Definition IKeyboard.hpp:93
@ KEY_APOSTROPHE
Definition IKeyboard.hpp:147
@ KEY_C
Definition IKeyboard.hpp:156
@ KEY_7
Definition IKeyboard.hpp:111
@ KEY_SLASH
Definition IKeyboard.hpp:163
@ KEY_L
Definition IKeyboard.hpp:145
@ KEY_F4
Definition IKeyboard.hpp:94
@ KEY_G
Definition IKeyboard.hpp:141
@ KEY_PAD_1
Definition IKeyboard.hpp:175
@ KEY_DOWN
Definition IKeyboard.hpp:191
@ KEY_5
Definition IKeyboard.hpp:109
@ KEY_F7
Definition IKeyboard.hpp:97
@ KEY_SEMICOLON
Definition IKeyboard.hpp:146
@ KEY_UP
ARROWS.
Definition IKeyboard.hpp:190
@ KEY_F2
Definition IKeyboard.hpp:92
@ KEY_ESCAPE
Line 0.
Definition IKeyboard.hpp:90
@ KEY_PAD_PLUS
Definition IKeyboard.hpp:185
@ KEY_Q
Definition IKeyboard.hpp:121
@ KEY_BACKSPACE
Definition IKeyboard.hpp:117
@ KEY_F9
Definition IKeyboard.hpp:99
@ KEY_E
Definition IKeyboard.hpp:123
@ KEY_O
Definition IKeyboard.hpp:129
@ KEY_1
Line 1.
Definition IKeyboard.hpp:105
@ KEY_6
Definition IKeyboard.hpp:110
@ KEY_B
Definition IKeyboard.hpp:158
@ KEY_S
Definition IKeyboard.hpp:138
@ KEY_RIGHT_BRACKET
Definition IKeyboard.hpp:132
@ KEY_PAD_3
Definition IKeyboard.hpp:177
@ KEY_PAD_5
Definition IKeyboard.hpp:179
@ KEY_LEFT_SUPER
Definition IKeyboard.hpp:167
@ KEY_EQUAL
Definition IKeyboard.hpp:116
@ KEY_RIGHT
Definition IKeyboard.hpp:193
@ KEY_PAD_7
Definition IKeyboard.hpp:181
@ KEY_M
Definition IKeyboard.hpp:160
@ KEY_RIGHT_CONTROL
Definition IKeyboard.hpp:171
@ KEY_F11
Definition IKeyboard.hpp:101
@ KEY_F
Definition IKeyboard.hpp:140
@ KEY_I
Definition IKeyboard.hpp:128
@ KEY_K
Definition IKeyboard.hpp:144
@ KEY_LEFT_SHIFT
Line 4.
Definition IKeyboard.hpp:152
@ KEY_P
Definition IKeyboard.hpp:130
@ KEY_PAD_MINUS
Definition IKeyboard.hpp:184
@ KEY_4
Definition IKeyboard.hpp:108
@ KEY_PAD_2
Definition IKeyboard.hpp:176
@ KEY_PAD_ENTER
Definition IKeyboard.hpp:187
@ KEY_F8
Definition IKeyboard.hpp:98
@ KEY_F5
Definition IKeyboard.hpp:95
@ KEY_0
Definition IKeyboard.hpp:114
@ KEY_A
Definition IKeyboard.hpp:137
@ KEY_LEFT_BRACKET
Definition IKeyboard.hpp:131
@ KEY_Z
Definition IKeyboard.hpp:154
@ KEY_N
Definition IKeyboard.hpp:159
@ KEY_RIGHT_SUPER
Definition IKeyboard.hpp:170
@ KEY_F6
Definition IKeyboard.hpp:96
@ KEY_J
Definition IKeyboard.hpp:143
@ KEY_PAD_4
Definition IKeyboard.hpp:178
@ KEY_LEFT
Definition IKeyboard.hpp:192
@ KEY_F1
Definition IKeyboard.hpp:91
@ KEY_W
Definition IKeyboard.hpp:122
@ KEY_BACKSLASH
Definition IKeyboard.hpp:153
@ KEY_RIGHT_ALT
Definition IKeyboard.hpp:169
@ KEY_PAD_DOT
Definition IKeyboard.hpp:186
@ KEY_F10
Definition IKeyboard.hpp:100
@ KEY_T
Definition IKeyboard.hpp:125
@ KEY_MINUS
Definition IKeyboard.hpp:115
@ KEY_Y
Definition IKeyboard.hpp:126
@ KEY_3
Definition IKeyboard.hpp:107
@ KEY_9
Definition IKeyboard.hpp:113
@ KEY_SPACE
Definition IKeyboard.hpp:168
@ KEY_PAD_8
Definition IKeyboard.hpp:182
@ KEY_D
Definition IKeyboard.hpp:139
@ KEY_TAB
Line 2.
Definition IKeyboard.hpp:120
@ KEY_PAD_0
KEYPAD.
Definition IKeyboard.hpp:174
@ KEY_V
Definition IKeyboard.hpp:157
@ KEY_RIGHT_SHIFT
Definition IKeyboard.hpp:164
@ KEY_8
Definition IKeyboard.hpp:112
@ KEY_U
Definition IKeyboard.hpp:127
@ KEY_LEFT_ALT
Line 5.
Definition IKeyboard.hpp:166
@ KEY_CAPS_LOCK
Line 3.
Definition IKeyboard.hpp:135
@ KEY_LEFT_CONTROL
Definition IKeyboard.hpp:136
@ KEY_COMMA
Definition IKeyboard.hpp:161
@ KEY_X
Definition IKeyboard.hpp:155
@ KEY_BACKTICK
Definition IKeyboard.hpp:148
@ KEY_H
Definition IKeyboard.hpp:142
@ KEY_PERIOD
Definition IKeyboard.hpp:162
@ KEY_ENTER
Definition IKeyboard.hpp:149
@ KEY_R
Definition IKeyboard.hpp:124
@ KEY_PAD_9
Definition IKeyboard.hpp:183
@ KEY_2
Definition IKeyboard.hpp:106
@ KEY_F12
Definition IKeyboard.hpp:102
@ KEY_PAD_6
Definition IKeyboard.hpp:180