MCPcopy Create free account
hub / github.com/dhewm/dhewm3 / KeyDownEvent

Method KeyDownEvent

neo/framework/Console.cpp:622–731  ·  view source on GitHub ↗

==================== KeyDownEvent Handles history and console scrollback ==================== */

Source from the content-addressed store, hash-verified

620====================
621*/
622void idConsoleLocal::KeyDownEvent( int key ) {
623
624 // Execute F key bindings
625 if ( key >= K_F1 && key <= K_F12 ) {
626 idKeyInput::ExecKeyBinding( key );
627 return;
628 }
629
630 // ctrl-L clears screen
631 if ( key == 'l' && idKeyInput::IsDown( K_CTRL ) ) {
632 Clear();
633 return;
634 }
635
636 // enter finishes the line
637 if ( key == K_ENTER || key == K_KP_ENTER ) {
638
639 common->Printf ( "]%s\n", consoleField.GetBuffer() );
640
641 cmdSystem->BufferCommandText( CMD_EXEC_APPEND, consoleField.GetBuffer() ); // valid command
642 cmdSystem->BufferCommandText( CMD_EXEC_APPEND, "\n" );
643
644 // copy line to history buffer, if it isn't the same as the last command
645 if ( idStr::Cmp( consoleField.GetBuffer(),
646 historyEditLines[(nextHistoryLine + COMMAND_HISTORY - 1) % COMMAND_HISTORY].GetBuffer()) != 0 )
647 {
648 historyEditLines[nextHistoryLine % COMMAND_HISTORY] = consoleField;
649 nextHistoryLine++;
650 }
651
652 historyLine = nextHistoryLine;
653 // clear the next line from old garbage, else the oldest history entry turns up when pressing DOWN
654 historyEditLines[nextHistoryLine % COMMAND_HISTORY].Clear();
655
656 consoleField.Clear();
657 consoleField.SetWidthInChars( LINE_WIDTH );
658
659 session->UpdateScreen();// force an update, because the command
660 // may take some time
661 return;
662 }
663
664 // command completion
665
666 if ( key == K_TAB ) {
667 consoleField.AutoComplete();
668 return;
669 }
670
671 // command history (ctrl-p ctrl-n for unix style)
672
673 if ( ( key == K_UPARROW ) ||
674 ( ( tolower(key) == 'p' ) && idKeyInput::IsDown( K_CTRL ) ) ) {
675 if ( nextHistoryLine - historyLine < COMMAND_HISTORY && historyLine > 0 ) {
676 historyLine--;
677 }
678 consoleField = historyEditLines[ historyLine % COMMAND_HISTORY ];
679 return;

Callers 1

Sys_ConsoleInputFunction · 0.45

Calls 9

ClearFunction · 0.85
GetBufferMethod · 0.80
BufferCommandTextMethod · 0.80
SetWidthInCharsMethod · 0.80
UpdateScreenMethod · 0.80
AutoCompleteMethod · 0.80
PrintfMethod · 0.45
ClearMethod · 0.45
MillisecondsMethod · 0.45

Tested by

no test coverage detected