MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / KeycodeToString

Function KeycodeToString

src/hotkeys.cpp:163–197  ·  view source on GitHub ↗

* Convert a hotkey to it's string representation so it can be written to the * config file. Separate parts of the keycode (like "CTRL" and "F1" are split * by a '+'. * @param keycode The keycode to convert to a string. * @return A string representation of this keycode. */

Source from the content-addressed store, hash-verified

161 * @return A string representation of this keycode.
162 */
163static std::string KeycodeToString(uint16_t keycode)
164{
165 std::string str;
166 if (keycode & WKC_GLOBAL_HOTKEY) {
167 str += "GLOBAL";
168 }
169 if (keycode & WKC_SHIFT) {
170 if (!str.empty()) str += "+";
171 str += "SHIFT";
172 }
173 if (keycode & WKC_CTRL) {
174 if (!str.empty()) str += "+";
175 str += "CTRL";
176 }
177 if (keycode & WKC_ALT) {
178 if (!str.empty()) str += "+";
179 str += "ALT";
180 }
181 if (keycode & WKC_META) {
182 if (!str.empty()) str += "+";
183 str += "META";
184 }
185 if (!str.empty()) str += "+";
186 keycode = keycode & ~WKC_SPECIAL_KEYS;
187
188 for (const auto &kn : _keycode_to_name) {
189 if (kn.keycode == keycode) {
190 str += kn.name;
191 return str;
192 }
193 }
194 assert(keycode < 128);
195 str.push_back(keycode);
196 return str;
197}
198
199/**
200 * Convert all keycodes attached to a hotkey to a single string. If multiple

Callers 1

SaveKeycodesFunction · 0.85

Calls 2

push_backMethod · 0.80
emptyMethod · 0.45

Tested by

no test coverage detected