The Battle for Wesnoth  1.15.0+dev
key.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2003 - 2018 by David White <dave@whitevine.net>
3  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details.
13 */
14 
15 #include "key.hpp"
16 
18  key_list(SDL_GetKeyboardState(nullptr))
19 {
20 }
21 
22 bool CKey::operator[](int k) const
23 {
24  return key_list[SDL_GetScancodeFromKey(k)] > 0;
25 }
26 
27 bool CKey::is_uncomposable(const SDL_KeyboardEvent &event) {
28 
29  switch (event.keysym.sym) {
30  case SDLK_RETURN:
31  case SDLK_ESCAPE:
32  case SDLK_BACKSPACE:
33  case SDLK_TAB:
34  // Function keys
35  case SDLK_F1:
36  case SDLK_F2:
37  case SDLK_F3:
38  case SDLK_F4:
39  case SDLK_F5:
40  case SDLK_F6:
41  case SDLK_F7:
42  case SDLK_F8:
43  case SDLK_F9:
44  case SDLK_F10:
45  case SDLK_F11:
46  case SDLK_F12:
47  case SDLK_F13:
48  case SDLK_F14:
49  case SDLK_F15:
50  case SDLK_F16:
51  case SDLK_F17:
52  case SDLK_F18:
53  case SDLK_F19:
54  case SDLK_F20:
55  case SDLK_F21:
56  case SDLK_F22:
57  case SDLK_F23:
58  case SDLK_F24:
59  // Keypad keys
60  case SDLK_KP_0:
61  case SDLK_KP_1:
62  case SDLK_KP_2:
63  case SDLK_KP_3:
64  case SDLK_KP_4:
65  case SDLK_KP_5:
66  case SDLK_KP_6:
67  case SDLK_KP_7:
68  case SDLK_KP_8:
69  case SDLK_KP_9:
70  case SDLK_KP_00:
71  case SDLK_KP_000:
72  case SDLK_KP_A:
73  case SDLK_KP_B:
74  case SDLK_KP_C:
75  case SDLK_KP_D:
76  case SDLK_KP_E:
77  case SDLK_KP_F:
78  case SDLK_KP_AMPERSAND:
79  case SDLK_KP_AT:
80  case SDLK_KP_BACKSPACE:
81  case SDLK_KP_BINARY:
82  case SDLK_KP_CLEAR:
83  case SDLK_KP_CLEARENTRY:
84  case SDLK_KP_COLON:
85  case SDLK_KP_COMMA:
86  case SDLK_KP_DBLAMPERSAND:
87  case SDLK_KP_DBLVERTICALBAR:
88  case SDLK_KP_DECIMAL:
89  case SDLK_KP_DIVIDE:
90  case SDLK_KP_ENTER:
91  case SDLK_KP_EQUALS:
92  case SDLK_KP_EQUALSAS400:
93  case SDLK_KP_EXCLAM:
94  case SDLK_KP_GREATER:
95  case SDLK_KP_HASH:
96  case SDLK_KP_HEXADECIMAL:
97  case SDLK_KP_LEFTBRACE:
98  case SDLK_KP_LEFTPAREN:
99  case SDLK_KP_LESS:
100  case SDLK_KP_MEMADD:
101  case SDLK_KP_MEMCLEAR:
102  case SDLK_KP_MEMDIVIDE:
103  case SDLK_KP_MEMMULTIPLY:
104  case SDLK_KP_MEMRECALL:
105  case SDLK_KP_MEMSTORE:
106  case SDLK_KP_MEMSUBTRACT:
107  case SDLK_KP_MINUS:
108  case SDLK_KP_MULTIPLY:
109  case SDLK_KP_OCTAL:
110  case SDLK_KP_PERCENT:
111  case SDLK_KP_PERIOD:
112  case SDLK_KP_PLUS:
113  case SDLK_KP_PLUSMINUS:
114  case SDLK_KP_POWER:
115  case SDLK_KP_RIGHTBRACE:
116  case SDLK_KP_RIGHTPAREN:
117  case SDLK_KP_SPACE:
118  case SDLK_KP_TAB:
119  case SDLK_KP_VERTICALBAR:
120  case SDLK_KP_XOR:
121  // Homepad keys
122  case SDLK_INSERT:
123  case SDLK_HOME:
124  case SDLK_PAGEUP:
125  case SDLK_PAGEDOWN:
126  case SDLK_DELETE:
127  case SDLK_END:
128  // Arrow keys
129  case SDLK_UP:
130  case SDLK_DOWN:
131  case SDLK_LEFT:
132  case SDLK_RIGHT:
133  case SDLK_SPACE:
134 
135  return true;
136  default:
137  return false;
138  }
139 }
bool operator[](int k) const
Definition: key.cpp:22
const uint8_t * key_list
Definition: key.hpp:29
static bool is_uncomposable(const SDL_KeyboardEvent &event)
Definition: key.cpp:27
CKey()
Definition: key.cpp:17