From a248e403d6a65eea03ace9be26b720d22e227e71 Mon Sep 17 00:00:00 2001 From: zeromus Date: Fri, 30 Oct 2009 05:24:52 +0000 Subject: [PATCH] fix bug preventing use of joysticks for hotkeys (even though they could be bound) --- desmume/src/windows/inputdx.h | 4 +++- desmume/src/windows/main.cpp | 36 +++++++++++++++++++++-------------- 2 files changed, 25 insertions(+), 15 deletions(-) diff --git a/desmume/src/windows/inputdx.h b/desmume/src/windows/inputdx.h index 567e66fac..9a2148d87 100644 --- a/desmume/src/windows/inputdx.h +++ b/desmume/src/windows/inputdx.h @@ -23,6 +23,8 @@ #ifndef INPUTDX_INCLUDED #define INPUTDX_INCLUDED +#include + typedef struct { COLORREF crForeGnd; // Foreground text colour @@ -78,7 +80,7 @@ struct SJoypad { struct SJoyState{ bool Attached; - //JOYCAPS Caps; + JOYCAPS Caps; int Threshold; bool Left; bool Right; diff --git a/desmume/src/windows/main.cpp b/desmume/src/windows/main.cpp index 190777754..56fcc7fc1 100644 --- a/desmume/src/windows/main.cpp +++ b/desmume/src/windows/main.cpp @@ -332,7 +332,8 @@ LRESULT CALLBACK WifiSettingsDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM static int KeyInDelayMSec = 0; static int KeyInRepeatMSec = 16; -VOID CALLBACK KeyInputTimer( UINT idEvent, UINT uMsg, DWORD_PTR dwUser, DWORD_PTR dw1, DWORD_PTR dw2) +template +static void InputTimer() { bool S9xGetState (WORD KeyIdent); @@ -355,30 +356,37 @@ VOID CALLBACK KeyInputTimer( UINT idEvent, UINT uMsg, DWORD_PTR dwUser, DWORD_PT initialized = true; } - for (int i = 0; i < 256; i++) { + for (int z = 0; z < 256; z++) { + int i = z | (JOYSTICK?0x8000:0); bool active = !S9xGetState(i); if (active) { - bool keyRepeat = (currentTime - joyState[i].firstPressedTime) >= (DWORD)KeyInDelayMSec; - if (!joyState[i].wasPressed || keyRepeat) { - if (!joyState[i].wasPressed) - joyState[i].firstPressedTime = currentTime; - joyState[i].lastPressedTime = currentTime; - if (keyRepeat && joyState[i].repeatCount < 0xffff) - joyState[i].repeatCount++; - PostMessage(MainWindow->getHWnd(), WM_CUSTKEYDOWN, (WPARAM)(i),(LPARAM)(joyState[i].repeatCount | (joyState[i].wasPressed ? 0x40000000 : 0))); + bool keyRepeat = (currentTime - joyState[z].firstPressedTime) >= (DWORD)KeyInDelayMSec; + if (!joyState[z].wasPressed || keyRepeat) { + if (!joyState[z].wasPressed) + joyState[z].firstPressedTime = currentTime; + joyState[z].lastPressedTime = currentTime; + if (keyRepeat && joyState[z].repeatCount < 0xffff) + joyState[z].repeatCount++; + PostMessage(MainWindow->getHWnd(), WM_CUSTKEYDOWN, (WPARAM)(i),(LPARAM)(joyState[z].repeatCount | (joyState[z].wasPressed ? 0x40000000 : 0))); } } else { - joyState[i].repeatCount = 1; - if (joyState[i].wasPressed) - PostMessage(MainWindow->getHWnd(), WM_CUSTKEYUP, (WPARAM)(i),(LPARAM)(joyState[i].repeatCount | (joyState[i].wasPressed ? 0x40000000 : 0))); + joyState[z].repeatCount = 1; + if (joyState[z].wasPressed) + PostMessage(MainWindow->getHWnd(), WM_CUSTKEYUP, (WPARAM)(i),(LPARAM)(joyState[z].repeatCount | (joyState[z].wasPressed ? 0x40000000 : 0))); } - joyState[i].wasPressed = active; + joyState[z].wasPressed = active; } lastTime = currentTime; } +VOID CALLBACK KeyInputTimer( UINT idEvent, UINT uMsg, DWORD_PTR dwUser, DWORD_PTR dw1, DWORD_PTR dw2) +{ + InputTimer(); + InputTimer(); +} + void ScaleScreen(float factor) { if(windowSize == 0)