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