Simplified AKD support

This commit is contained in:
tomcw 2018-06-02 22:26:29 +01:00
parent 539f5db40a
commit fdd6a622dc
4 changed files with 47 additions and 98 deletions

View File

@ -1260,10 +1260,6 @@ LRESULT CALLBACK FrameWndProc (
case WM_KEYDOWN:
KeybUpdateCtrlShiftStatus();
KeybSpecialKeyTransition(WM_KEYDOWN, wparam);
if ((HIWORD(lparam) & KF_REPEAT) == 0)
KeybAnyKeyDown(WM_KEYDOWN, wparam);
// Process is done in WM_KEYUP: VK_F1 VK_F2 VK_F3 VK_F4 VK_F5 VK_F6 VK_F7 VK_F8
if ((wparam >= VK_F1) && (wparam <= VK_F8) && (buttondown == -1))
@ -1389,11 +1385,18 @@ LRESULT CALLBACK FrameWndProc (
// Note about Alt Gr (Right-Alt):
// . WM_KEYDOWN[Left-Control], then:
// . WM_KEYDOWN[Right-Alt]
BOOL extended = ((lparam & 0x01000000) != 0);
BOOL extended = (HIWORD(lparam) & KF_EXTENDED) != 0;
BOOL down = 1;
BOOL autorep = ((lparam & 0x40000000) != 0);
if ((!JoyProcessKey((int)wparam,extended,down,autorep)) && (g_nAppMode != MODE_LOGO))
KeybQueueKeypress((int)wparam,NOT_ASCII);
BOOL autorep = (HIWORD(lparam) & KF_REPEAT) != 0;
BOOL IsJoyKey = JoyProcessKey((int)wparam, extended, down, autorep);
if (!IsJoyKey && (g_nAppMode != MODE_LOGO))
{
KeybQueueKeypress((int)wparam, NOT_ASCII);
if ((HIWORD(lparam) & KF_REPEAT) == 0)
KeybAnyKeyDown(WM_KEYDOWN, wparam);
}
}
else if (g_nAppMode == MODE_DEBUG)
{
@ -1402,9 +1405,6 @@ LRESULT CALLBACK FrameWndProc (
break;
case WM_KEYUP:
KeybSpecialKeyTransition(WM_KEYUP, wparam);
KeybAnyKeyDown(WM_KEYUP, wparam);
// Process is done in WM_KEYUP: VK_F1 VK_F2 VK_F3 VK_F4 VK_F5 VK_F6 VK_F7 VK_F8
if ((wparam >= VK_F1) && (wparam <= VK_F8) && (buttondown == (int)wparam-VK_F1))
{
@ -1417,10 +1417,13 @@ LRESULT CALLBACK FrameWndProc (
}
else
{
BOOL extended = ((lparam & 0x01000000) != 0);
BOOL extended = (HIWORD(lparam) & KF_EXTENDED) != 0;
BOOL down = 0;
BOOL autorep = 0;
JoyProcessKey((int)wparam,extended,down,autorep);
BOOL bIsJoyKey = JoyProcessKey((int)wparam, extended, down, autorep);
if (!bIsJoyKey)
KeybAnyKeyDown(WM_KEYUP, wparam);
}
break;

View File

@ -390,55 +390,17 @@ static char ClipboardCurrChar(bool bIncPtr)
//===========================================================================
// For AKD (Any Key Down), need special handling for the hooked key combos(*), as GetKeyState() doesn't detect the keys as being up/down.
// . EG. Whilst pressing TAB, press LEFT ALT, then release TAB.
// (*) ALT+TAB, ALT+ESCAPE, ALT+SPACE
static enum {AKD_TAB=0, AKD_ESCAPE, AKD_SPACE, AKD_RETURN};
static bool g_specialAKD[4] = {false,false,false,false};
void KeybSpecialKeyTransition(UINT message, WPARAM wparam)
{
_ASSERT(message == WM_KEYUP || message == WM_KEYDOWN);
bool bState = message == WM_KEYDOWN;
switch (wparam)
{
case VK_TAB:
g_specialAKD[AKD_TAB] = bState;
break;
case VK_ESCAPE:
g_specialAKD[AKD_ESCAPE] = bState;
break;
case VK_SPACE:
g_specialAKD[AKD_SPACE] = bState;
break;
case VK_RETURN: // Treat as special too, as get a WM_KEYUP after using RETURN to OK the Config/Load-State dialogs!
g_specialAKD[AKD_RETURN] = bState;
break;
};
}
static void GetKeyStateOfSpecialAKD(bool& bState)
{
if ( g_specialAKD[AKD_TAB] || g_specialAKD[AKD_ESCAPE] || g_specialAKD[AKD_SPACE] || g_specialAKD[AKD_RETURN] )
bState = true;
}
//===========================================================================
static int g_AKDRefCount = 0;
static uint64_t g_AKDFlags[4] = {0,0,0,0};
// NB. Don't need to be concerned about if numpad/cursors are used for joystick,
// since parent calls JoyProcessKey() just before this.
void KeybAnyKeyDown(UINT message, WPARAM wparam)
{
if (IS_APPLE2) // Include Pravets machines too?
return; // No AKD support
if (wparam == VK_TAB || wparam == VK_ESCAPE || wparam == VK_SPACE || wparam == VK_RETURN)
return; // Could be from hook-filter, so ignore and handle via KeybSpecialKeyTransition()
const int value = message == WM_KEYDOWN ? 1 : -1;
bool bDoRefCount = false;
if (wparam > 255)
{
_ASSERT(0);
return;
}
if (wparam == VK_BACK ||
wparam == VK_TAB ||
@ -448,52 +410,38 @@ void KeybAnyKeyDown(UINT message, WPARAM wparam)
(wparam >= VK_LEFT && wparam <= VK_DOWN) ||
wparam == VK_DELETE ||
(wparam >= '0' && wparam <= '9') ||
(wparam >= 'A' && wparam <= 'Z'))
(wparam >= 'A' && wparam <= 'Z') ||
(wparam >= VK_NUMPAD0 && wparam <= VK_NUMPAD9) ||
(wparam >= VK_MULTIPLY && wparam <= VK_DIVIDE) ||
(wparam >= VK_OEM_1 && wparam <= VK_OEM_3) || // 7 in total
(wparam >= VK_OEM_4 && wparam <= VK_OEM_8) || // 5 in total
(wparam == VK_OEM_102))
{
bDoRefCount = true;
}
else if (wparam >= VK_NUMPAD0 && wparam <= VK_NUMPAD9)
{
bDoRefCount = true;
}
else if (wparam >= VK_MULTIPLY && wparam <= VK_DIVIDE)
{
bDoRefCount = true;
}
else if (wparam >= VK_OEM_1 && wparam <= VK_OEM_3) // 7 in total
{
bDoRefCount = true;
}
else if (wparam >= VK_OEM_4 && wparam <= VK_OEM_8) // 5 in total
{
bDoRefCount = true;
}
else if (wparam == VK_OEM_102)
{
bDoRefCount = true;
}
UINT offset = wparam >> 6;
UINT bit = wparam & 0x3f;
if (bDoRefCount)
{
g_AKDRefCount += value;
if (g_AKDRefCount < 0)
{
_ASSERT(0);
g_AKDRefCount = 0;
}
if (message == WM_KEYDOWN)
g_AKDFlags[offset] |= (1LL<<bit);
else
g_AKDFlags[offset] &= ~(1LL<<bit);
}
}
static bool IsAKD(void)
{
return g_AKDFlags[0] || g_AKDFlags[1] || g_AKDFlags[2] || g_AKDFlags[3];
}
//===========================================================================
BYTE __stdcall KeybReadData (WORD, WORD, BYTE, BYTE, ULONG)
{
LogFileTimeUntilFirstKeyRead();
if(g_bPasteFromClipboard)
if (g_bPasteFromClipboard)
ClipboardInit();
if(g_bClipboardActive)
if (g_bClipboardActive)
{
if(*lptstr == 0)
ClipboardDone();
@ -510,10 +458,10 @@ BYTE __stdcall KeybReadData (WORD, WORD, BYTE, BYTE, ULONG)
BYTE __stdcall KeybReadFlag (WORD, WORD, BYTE, BYTE, ULONG)
{
if(g_bPasteFromClipboard)
if (g_bPasteFromClipboard)
ClipboardInit();
if(g_bClipboardActive)
if (g_bClipboardActive)
{
if(*lptstr == 0)
ClipboardDone();
@ -530,9 +478,7 @@ BYTE __stdcall KeybReadFlag (WORD, WORD, BYTE, BYTE, ULONG)
// AKD
bool bState = g_AKDRefCount > 0;
GetKeyStateOfSpecialAKD(bState);
return keycode | (bState ? 0x80 : 0);
return keycode | (IsAKD() ? 0x80 : 0);
}
//===========================================================================

View File

@ -14,7 +14,6 @@ BYTE KeybGetKeycode ();
void KeybQueueKeypress (int,BOOL);
void KeybToggleCapsLock ();
void KeybToggleP8ACapsLock ();
void KeybSpecialKeyTransition(UINT message, WPARAM wparam);
void KeybAnyKeyDown(UINT message, WPARAM wparam);
void KeybSetSnapshot_v1(const BYTE LastKey);
void KeybSaveSnapshot(class YamlSaveHelper& yamlSaveHelper);

View File

@ -31,6 +31,7 @@
typedef UINT8 uint8_t;
typedef UINT16 uint16_t;
typedef UINT32 uint32_t;
typedef UINT64 uint64_t;
#endif
#include <windows.h>