Skip to content

Commit 844c436

Browse files
authored
bugfix(input): Disable mouse waypoint mode after using alt tab (#1987)
1 parent ce4e595 commit 844c436

File tree

6 files changed

+54
-4
lines changed

6 files changed

+54
-4
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)

GeneralsMD/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

GeneralsMD/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
//-------------------------------------------------------------------------------------------------

GeneralsMD/Code/Main/WinMain.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ LRESULT CALLBACK WndProc( HWND hWnd, UINT message,
423423
// reset the state of our keyboard cause we haven't been paying
424424
// attention to the keys while focus was away
425425
//
426-
if( TheKeyboard )
426+
if (TheKeyboard)
427427
TheKeyboard->resetKeys();
428428

429429
if (TheMouse)
@@ -435,7 +435,7 @@ LRESULT CALLBACK WndProc( HWND hWnd, UINT message,
435435
//-------------------------------------------------------------------------
436436
case WM_KILLFOCUS:
437437
{
438-
if (TheKeyboard )
438+
if (TheKeyboard)
439439
TheKeyboard->resetKeys();
440440

441441
if (TheMouse)

0 commit comments

Comments
 (0)