Skip to content

Commit

Permalink
WWKeyboardClass' KeyState buffer is Win32 only, so mark it as such.
Browse files Browse the repository at this point in the history
  • Loading branch information
isojalka authored and hifi committed Mar 16, 2024
1 parent f52d4d2 commit f4cc9b0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
31 changes: 17 additions & 14 deletions common/wwkeyboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,10 @@ WWKeyboardClass::WWKeyboardClass(void)
, Tail(0)
, DownSkip(0)
{
#if defined(_WIN32)
memset(KeyState, '\0', sizeof(KeyState));
#endif

memset(DownState, '\0', sizeof(DownState));
}

Expand Down Expand Up @@ -297,19 +300,6 @@ KeyASCIIType WWKeyboardClass::To_ASCII(unsigned short key)
return KA_NONE;
}

/*
** Set the KeyState buffer to reflect the shift bits stored in the key value.
*/
if (key & WWKEY_SHIFT_BIT) {
KeyState[VK_SHIFT] = 0x80;
}
if (key & WWKEY_CTRL_BIT) {
KeyState[VK_CONTROL] = 0x80;
}
if (key & WWKEY_ALT_BIT) {
KeyState[VK_MENU] = 0x80;
}

/*
** Ask windows to translate the key into an ASCII equivalent.
*/
Expand All @@ -330,9 +320,21 @@ KeyASCIIType WWKeyboardClass::To_ASCII(unsigned short key)
return sdl_keymap[key];
}
#elif defined(_WIN32)
/*
** Set the KeyState buffer to reflect the shift bits stored in the key value.
*/
if (key & WWKEY_SHIFT_BIT) {
KeyState[VK_SHIFT] = 0x80;
}
if (key & WWKEY_CTRL_BIT) {
KeyState[VK_CONTROL] = 0x80;
}
if (key & WWKEY_ALT_BIT) {
KeyState[VK_MENU] = 0x80;
}

scancode = MapVirtualKeyA(key & 0xFF, 0);
result = ToAscii((UINT)(key & 0xFF), (UINT)scancode, (PBYTE)KeyState, (LPWORD)buffer, (UINT)0);
#endif

/*
** Restore the KeyState buffer back to pristine condition.
Expand All @@ -346,6 +348,7 @@ KeyASCIIType WWKeyboardClass::To_ASCII(unsigned short key)
if (key & WWKEY_ALT_BIT) {
KeyState[VK_MENU] = 0;
}
#endif

/*
** If Windows could not perform the translation as expected, then
Expand Down
2 changes: 2 additions & 0 deletions common/wwkeyboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -900,7 +900,9 @@ class WWKeyboardClass
** This is a keyboard state array that is used to aid in translating
** KN_ keys into KA_ keys.
*/
#if defined(_WIN32)
unsigned char KeyState[256];
#endif

/*
** This is the circular keyboard holding buffer. It holds the VK key and
Expand Down

0 comments on commit f4cc9b0

Please sign in to comment.