Skip to content

Commit 283039c

Browse files
committed
Replicated in Generals.
1 parent 9814520 commit 283039c

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

Generals/Code/GameEngine/Include/GameClient/Keyboard.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,8 @@ class Keyboard : public SubsystemInterface
119119
WideChar translateKey( WideChar keyCode ); ///< translate key code to printable UNICODE char
120120
WideChar getPrintableKey( KeyDefType key, Int state );
121121
enum { MAX_KEY_STATES = 3};
122+
private:
123+
void refreshAltKeys() const; ///< refresh the state of the alt keys, necessary after alt tab
122124
protected:
123125

124126
/** get the key data for a single key, KEY_NONE should be returned when

Generals/Code/GameEngine/Source/GameClient/Input/Keyboard.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -748,6 +748,10 @@ void Keyboard::update( void )
748748
void Keyboard::resetKeys( void )
749749
{
750750

751+
// TheSuperHackers @fix Caball009 13/12/2025 Fix bug where game remains in waypoint mode
752+
// because the key up state for the alt key is not detected after alt tab.
753+
refreshAltKeys();
754+
751755
memset( m_keys, 0, sizeof( m_keys ) );
752756
memset( m_keyStatus, 0, sizeof( m_keyStatus ) );
753757
m_modifiers = KEY_STATE_NONE;
@@ -758,6 +762,25 @@ void Keyboard::resetKeys( void )
758762

759763
}
760764

765+
//-------------------------------------------------------------------------------------------------
766+
// Refresh the state of the alt keys, necessary after alt tab
767+
//-------------------------------------------------------------------------------------------------
768+
void Keyboard::refreshAltKeys() const
769+
{
770+
if (BitIsSet(m_keyStatus[KEY_LALT].state, KEY_STATE_DOWN))
771+
{
772+
GameMessage* msg = TheMessageStream->appendMessage(GameMessage::MSG_RAW_KEY_UP);
773+
msg->appendIntegerArgument(KEY_LALT);
774+
msg->appendIntegerArgument(KEY_STATE_UP);
775+
}
776+
if (BitIsSet(m_keyStatus[KEY_RALT].state, KEY_STATE_DOWN))
777+
{
778+
GameMessage* msg = TheMessageStream->appendMessage(GameMessage::MSG_RAW_KEY_UP);
779+
msg->appendIntegerArgument(KEY_RALT);
780+
msg->appendIntegerArgument(KEY_STATE_UP);
781+
}
782+
}
783+
761784
//-------------------------------------------------------------------------------------------------
762785
/** get the first key in our current state of the keyboard */
763786
//-------------------------------------------------------------------------------------------------

Generals/Code/Main/WinMain.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ LRESULT CALLBACK WndProc( HWND hWnd, UINT message,
401401
// reset the state of our keyboard cause we haven't been paying
402402
// attention to the keys while focus was away
403403
//
404-
if( TheKeyboard )
404+
if (TheKeyboard)
405405
TheKeyboard->resetKeys();
406406

407407
if (TheMouse)
@@ -413,7 +413,7 @@ LRESULT CALLBACK WndProc( HWND hWnd, UINT message,
413413
//-------------------------------------------------------------------------
414414
case WM_KILLFOCUS:
415415
{
416-
if (TheKeyboard )
416+
if (TheKeyboard)
417417
TheKeyboard->resetKeys();
418418

419419
if (TheMouse)

0 commit comments

Comments
 (0)