From 29c0f1e4f0b99fb6bd0fccaacedd43e0134f66bf Mon Sep 17 00:00:00 2001 From: tomcw Date: Tue, 7 Jan 2020 21:59:06 +0000 Subject: [PATCH] Cmd line support for remapping button0&1: (#743) . -left-control-alt-buttons : l-ctrl=button0, l-alt=button1 . -right-alt-control-buttons : r-alt=button0, r-ctrl=button1 . -swap-buttons --- source/Applewin.cpp | 14 ++++++++++++++ source/Joystick.cpp | 28 ++++++++++++++++++++++++++-- source/Joystick.h | 2 ++ 3 files changed, 42 insertions(+), 2 deletions(-) diff --git a/source/Applewin.cpp b/source/Applewin.cpp index 52777d4f..8b972a94 100644 --- a/source/Applewin.cpp +++ b/source/Applewin.cpp @@ -1576,6 +1576,20 @@ static void ProcessCmdLine(LPSTR lpCmdLine) { JoySetHookAltKeys(false); } + else if (strcmp(lpCmdLine, "-left-control-alt-buttons") == 0) + { + JoySetButtonVirtualKey(0, VK_CONTROL); + JoySetButtonVirtualKey(1, VK_MENU); + } + else if (strcmp(lpCmdLine, "-right-alt-control-buttons") == 0) + { + JoySetButtonVirtualKey(0, VK_MENU | KF_EXTENDED); + JoySetButtonVirtualKey(1, VK_CONTROL | KF_EXTENDED); + } + else if (strcmp(lpCmdLine, "-swap-buttons") == 0) + { + JoySwapButton0and1(true); + } else if (strcmp(lpCmdLine, "-spkr-inc") == 0) { lpCmdLine = GetCurrArg(lpNextArg); diff --git a/source/Joystick.cpp b/source/Joystick.cpp index a7edb82a..37b5ae9f 100644 --- a/source/Joystick.cpp +++ b/source/Joystick.cpp @@ -303,6 +303,24 @@ void JoyInitialize() //=========================================================================== +static bool g_swapButton0and1 = false; + +void JoySwapButton0and1(bool swap) +{ + g_swapButton0and1 = swap; +} + +static UINT g_buttonVirtKey[2] = { VK_MENU, VK_MENU | KF_EXTENDED }; + +void JoySetButtonVirtualKey(UINT button, UINT virtKey) +{ + _ASSERT(button < 2); + if (button >= 2) return; + g_buttonVirtKey[button] = virtKey; +} + +//=========================================================================== + #define SUPPORT_CURSOR_KEYS BOOL JoyProcessKey(int virtkey, bool extended, bool down, bool autorep) @@ -330,11 +348,17 @@ BOOL JoyProcessKey(int virtkey, bool extended, bool down, bool autorep) BOOL keychange = 0; bool bIsCursorKey = false; + UINT virtKeyWithExtended = ((UINT)virtkey) | (extended ? KF_EXTENDED : 0); - if (virtkey == VK_MENU) // VK_MENU == ALT Key (Button #0 or #1) + if (virtKeyWithExtended == g_buttonVirtKey[!g_swapButton0and1 ? 0 : 1]) { keychange = 1; - keydown[JK_OPENAPPLE+(extended != 0)] = down; + keydown[JK_OPENAPPLE] = down; + } + else if (virtKeyWithExtended == g_buttonVirtKey[!g_swapButton0and1 ? 1 : 0]) + { + keychange = 1; + keydown[JK_CLOSEDAPPLE] = down; } else if (!extended) { diff --git a/source/Joystick.h b/source/Joystick.h index 668d650a..d56f0637 100644 --- a/source/Joystick.h +++ b/source/Joystick.h @@ -25,6 +25,8 @@ void JoySetTrim(short nValue, bool bAxisX); short JoyGetTrim(bool bAxisX); void JoyportControl(const UINT uControl); void JoySetHookAltKeys(bool hook); +void JoySwapButton0and1(bool swap); +void JoySetButtonVirtualKey(UINT button, UINT virtKey); void JoySaveSnapshot(class YamlSaveHelper& yamlSaveHelper); void JoyLoadSnapshot(class YamlLoadHelper& yamlLoadHelper);