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

Method OnKeyPress

src/console_gui.cpp:239–319  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

237 }
238
239 EventState OnKeyPress([[maybe_unused]] char32_t key, uint16_t keycode) override
240 {
241 if (_focused_window != this) return ES_NOT_HANDLED;
242
243 const int scroll_height = (this->height / this->line_height) - 1;
244 switch (keycode) {
245 case WKC_UP:
246 IConsoleHistoryNavigate(1);
247 this->SetDirty();
248 break;
249
250 case WKC_DOWN:
251 IConsoleHistoryNavigate(-1);
252 this->SetDirty();
253 break;
254
255 case WKC_SHIFT | WKC_PAGEDOWN:
256 this->Scroll(-scroll_height);
257 break;
258
259 case WKC_SHIFT | WKC_PAGEUP:
260 this->Scroll(scroll_height);
261 break;
262
263 case WKC_SHIFT | WKC_DOWN:
264 this->Scroll(-1);
265 break;
266
267 case WKC_SHIFT | WKC_UP:
268 this->Scroll(1);
269 break;
270
271 case WKC_BACKQUOTE:
272 IConsoleSwitch();
273 break;
274
275 case WKC_RETURN: case WKC_NUM_ENTER: {
276 /* We always want the ] at the left side; we always force these strings to be left
277 * aligned anyway. So enforce this in all cases by adding a left-to-right marker,
278 * otherwise it will be drawn at the wrong side with right-to-left texts. */
279 IConsolePrint(CC_COMMAND, LRM "] {}", _iconsole_cmdline.GetText());
280 auto cmd = IConsoleHistoryAdd(_iconsole_cmdline.GetText());
281 IConsoleClearCommand();
282
283 if (cmd.has_value()) IConsoleCmdExec(*cmd);
284 break;
285 }
286
287 case WKC_CTRL | WKC_RETURN:
288 _iconsole_mode = (_iconsole_mode == ICONSOLE_FULL) ? ICONSOLE_OPENED : ICONSOLE_FULL;
289 IConsoleResize(this);
290 MarkWholeScreenDirty();
291 break;
292
293 case (WKC_CTRL | 'L'):
294 IConsoleCmdExec("clear");
295 break;
296

Callers

nothing calls this directly

Calls 15

ScrollMethod · 0.95
IConsoleHistoryNavigateFunction · 0.85
IConsoleSwitchFunction · 0.85
IConsoleHistoryAddFunction · 0.85
IConsoleClearCommandFunction · 0.85
IConsoleCmdExecFunction · 0.85
IConsoleResizeFunction · 0.85
MarkWholeScreenDirtyFunction · 0.85
IConsoleResetHistoryPosFunction · 0.85
AutoCompleteMethod · 0.80
HandleKeyPressMethod · 0.80
IConsolePrintFunction · 0.70

Tested by

no test coverage detected