The Battle for Wesnoth  1.19.0-dev
key.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2003 - 2024
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_ESCAPE:
33  case SDLK_BACKSPACE:
34  case SDLK_TAB:
35  // Function keys
36  case SDLK_F1:
37  case SDLK_F2:
38  case SDLK_F3:
39  case SDLK_F4:
40  case SDLK_F5:
41  case SDLK_F6:
42  case SDLK_F7:
43  case SDLK_F8:
44  case SDLK_F9:
45  case SDLK_F10:
46  case SDLK_F11:
47  case SDLK_F12:
48  case SDLK_F13:
49  case SDLK_F14:
50  case SDLK_F15:
51  case SDLK_F16:
52  case SDLK_F17:
53  case SDLK_F18:
54  case SDLK_F19:
55  case SDLK_F20:
56  case SDLK_F21:
57  case SDLK_F22:
58  case SDLK_F23:
59  case SDLK_F24:
60  // Keypad keys
61  case SDLK_KP_0:
62  case SDLK_KP_1:
63  case SDLK_KP_2:
64  case SDLK_KP_3:
65  case SDLK_KP_4:
66  case SDLK_KP_5:
67  case SDLK_KP_6:
68  case SDLK_KP_7:
69  case SDLK_KP_8:
70  case SDLK_KP_9:
71  case SDLK_KP_00:
72  case SDLK_KP_000:
73  case SDLK_KP_A:
74  case SDLK_KP_B:
75  case SDLK_KP_C:
76  case SDLK_KP_D:
77  case SDLK_KP_E:
78  case SDLK_KP_F:
79  case SDLK_KP_AMPERSAND:
80  case SDLK_KP_AT:
81  case SDLK_KP_BACKSPACE:
82  case SDLK_KP_BINARY:
83  case SDLK_KP_CLEAR:
84  case SDLK_KP_CLEARENTRY:
85  case SDLK_KP_COLON:
86  case SDLK_KP_COMMA:
87  case SDLK_KP_DBLAMPERSAND:
88  case SDLK_KP_DBLVERTICALBAR:
89  case SDLK_KP_DECIMAL:
90  case SDLK_KP_DIVIDE:
91  case SDLK_KP_ENTER:
92  case SDLK_KP_EQUALS:
93  case SDLK_KP_EQUALSAS400:
94  case SDLK_KP_EXCLAM:
95  case SDLK_KP_GREATER:
96  case SDLK_KP_HASH:
97  case SDLK_KP_HEXADECIMAL:
98  case SDLK_KP_LEFTBRACE:
99  case SDLK_KP_LEFTPAREN:
100  case SDLK_KP_LESS:
101  case SDLK_KP_MEMADD:
102  case SDLK_KP_MEMCLEAR:
103  case SDLK_KP_MEMDIVIDE:
104  case SDLK_KP_MEMMULTIPLY:
105  case SDLK_KP_MEMRECALL:
106  case SDLK_KP_MEMSTORE:
107  case SDLK_KP_MEMSUBTRACT:
108  case SDLK_KP_MINUS:
109  case SDLK_KP_MULTIPLY:
110  case SDLK_KP_OCTAL:
111  case SDLK_KP_PERCENT:
112  case SDLK_KP_PERIOD:
113  case SDLK_KP_PLUS:
114  case SDLK_KP_PLUSMINUS:
115  case SDLK_KP_POWER:
116  case SDLK_KP_RIGHTBRACE:
117  case SDLK_KP_RIGHTPAREN:
118  case SDLK_KP_SPACE:
119  case SDLK_KP_TAB:
120  case SDLK_KP_VERTICALBAR:
121  case SDLK_KP_XOR:
122  // Homepad keys
123  case SDLK_INSERT:
124  case SDLK_HOME:
125  case SDLK_PAGEUP:
126  case SDLK_PAGEDOWN:
127  case SDLK_DELETE:
128  case SDLK_END:
129  // Arrow keys
130  case SDLK_UP:
131  case SDLK_DOWN:
132  case SDLK_LEFT:
133  case SDLK_RIGHT:
134  case SDLK_SPACE:
135 
136  return true;
137  default:
138  return false;
139  }
140 }
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...