added a simple printing of the key/button pressed (#567)

added a simple helper print method to know what key/button is being pressed,
controlled via a bool cvar "in_namePressed" 1 or 0.
I tested it and it works with keyboard, mouse and gamepad.
This commit is contained in:
Biel Bestué de Luna 2024-03-25 02:15:20 +01:00 committed by Daniel Gibson
parent fb5eedb35f
commit 3504e693bf
2 changed files with 19 additions and 0 deletions

View file

@ -196,6 +196,8 @@ static const keyname_t keynames[] =
{NULL, 0, NULL}
};
idCVar in_namePressed( "in_namePressed", "0", CVAR_BOOL|CVAR_SYSTEM, "print the name of the key/button pressed" );
static const int MAX_KEYS = K_LAST_KEY+1; // DG: was 256, made it more flexible
class idKey {
@ -758,6 +760,10 @@ Called by the system for both key up and key down events
void idKeyInput::PreliminaryKeyEvent( int keynum, bool down ) {
keys[keynum].down = down;
if( cvarSystem->GetCVarBool( "in_namePressed") ) {
KeyReveal( keynum );
}
#ifdef ID_DOOM_LEGACY
if ( down && keynum < 127 ) { // DG: only ASCII keys are of interest here
lastKeys[ 0 + ( lastKeyIndex & 15 )] = keynum;
@ -775,6 +781,18 @@ void idKeyInput::PreliminaryKeyEvent( int keynum, bool down ) {
#endif
}
/*
===================
idKeyInput::KeyReveal
simple print in the console the name of the key pressed
===================
*/
void idKeyInput::KeyReveal( int keyNum ) {
const char* keyName = KeyNumToString( keyNum, false );
common->Printf( "pressed the \"%s\" key.\n", keyName );
}
/*
=================
idKeyInput::ExecKeyBinding

View file

@ -312,6 +312,7 @@ public:
static const char * BindingFromKey( const char *key );
static bool KeyIsBoundTo( int keyNum, const char *binding );
static void WriteBindings( idFile *f );
static void KeyReveal( int keyNum );
};
#endif /* !__KEYINPUT_H__ */