From: Toni Wilen Date: Sun, 14 May 2017 16:43:48 +0000 (+0300) Subject: Release pressed keys when unpaused. X-Git-Tag: 3500~31 X-Git-Url: https://git.unchartedbackwaters.co.uk/w/?a=commitdiff_plain;h=04fdd4cb4db26d3026fec6cbd957441da9693cb3;p=francis%2Fwinuae.git Release pressed keys when unpaused. --- diff --git a/include/inputdevice.h b/include/inputdevice.h index 80c5e0f2..7b1143f6 100644 --- a/include/inputdevice.h +++ b/include/inputdevice.h @@ -256,7 +256,7 @@ extern void inputdevice_devicechange (struct uae_prefs *prefs); extern void send_internalevent (int eventid); -extern int inputdevice_translatekeycode (int keyboard, int scancode, int state); +extern int inputdevice_translatekeycode (int keyboard, int scancode, int state, bool alwaysrelease); extern void inputdevice_checkqualifierkeycode (int keyboard, int scancode, int state); extern void inputdevice_setkeytranslation (struct uae_input_device_kbr_default **trans, int **kbmaps); extern void inputdevice_do_keyboard (int code, int state); diff --git a/inputdevice.cpp b/inputdevice.cpp index f75a9104..8d6d8c34 100644 --- a/inputdevice.cpp +++ b/inputdevice.cpp @@ -3957,18 +3957,6 @@ static uae_u8 keybuf[256]; #define MAX_PENDING_EVENTS 20 static int inputcode_pending[MAX_PENDING_EVENTS], inputcode_pending_state[MAX_PENDING_EVENTS]; -static void inputdevice_release_all_keys (void) -{ - int i; - - for (i = 0; i < 0x80; i++) { - if (keybuf[i] != 0) { - keybuf[i] = 0; - record_key (i << 1|1); - } - } -} - static bool inputdevice_handle_inputcode_immediate(int code, int state) { switch(code) @@ -7321,7 +7309,7 @@ int inputdevice_synccapslock (int oldcaps, int *capstable) if (na->extra[j] == capstable[i]) { if (oldcaps != capstable[i + 1]) { oldcaps = capstable[i + 1]; - inputdevice_translatekeycode (0, capstable[i], oldcaps ? -1 : 0); + inputdevice_translatekeycode (0, capstable[i], oldcaps ? -1 : 0, false); } return i; } @@ -7364,7 +7352,7 @@ static void rqualifiers (uae_u64 flags, bool release) } } -static int inputdevice_translatekeycode_2 (int keyboard, int scancode, int keystate, bool qualifiercheckonly) +static int inputdevice_translatekeycode_2 (int keyboard, int scancode, int keystate, bool qualifiercheckonly, bool ignorecanrelease) { struct uae_input_device *na = &keyboards[keyboard]; int j, k; @@ -7477,6 +7465,8 @@ static int inputdevice_translatekeycode_2 (int keyboard, int scancode, int keyst if (!invert) *flagsp |= ID_FLAG_CANRELEASE; } else { + if (ignorecanrelease) + flags |= ID_FLAG_CANRELEASE; if (!(flags & ID_FLAG_CANRELEASE) && !invert) continue; *flagsp &= ~ID_FLAG_CANRELEASE; @@ -7522,13 +7512,13 @@ static void sendmmcodes (int code, int newstate) } // main keyboard press/release entry point -int inputdevice_translatekeycode (int keyboard, int scancode, int state) +int inputdevice_translatekeycode (int keyboard, int scancode, int state, bool alwaysrelease) { // if not default keyboard and all events are empty: use default keyboard if (!input_get_default_keyboard(keyboard) && isemptykey(keyboard, scancode)) { keyboard = input_get_default_keyboard(-1); } - if (inputdevice_translatekeycode_2 (keyboard, scancode, state, false)) + if (inputdevice_translatekeycode_2 (keyboard, scancode, state, false, alwaysrelease)) return 1; if (currprefs.mmkeyboard && scancode > 0) { sendmmcodes (scancode, state); @@ -7538,7 +7528,7 @@ int inputdevice_translatekeycode (int keyboard, int scancode, int state) } void inputdevice_checkqualifierkeycode (int keyboard, int scancode, int state) { - inputdevice_translatekeycode_2 (keyboard, scancode, state, true); + inputdevice_translatekeycode_2 (keyboard, scancode, state, true, false); } static const TCHAR *internaleventlabels[] = { diff --git a/od-win32/dinput.cpp b/od-win32/dinput.cpp index 678dd0df..64f19cb6 100644 --- a/od-win32/dinput.cpp +++ b/od-win32/dinput.cpp @@ -23,6 +23,7 @@ int no_windowsmouse = 0; #define RAWINPUT_DEBUG 0 #define DI_DEBUG 1 #define IGNOREEVERYTHING 0 +#define DEBUG_SCANCODE 0 #define NEGATIVEMINHACK 0 @@ -555,8 +556,8 @@ static int keyhack (int scancode, int pressed, int num) static byte backslashstate, apostrophstate; //check ALT-F4 - if (pressed && !di_keycodes[num][DIK_F4] && scancode == DIK_F4) { - if (di_keycodes[num][DIK_LALT] && !currprefs.win32_ctrl_F11_is_quit) { + if (pressed && !(di_keycodes[num][DIK_F4] & 1) && scancode == DIK_F4) { + if ((di_keycodes[num][DIK_LALT] & 1) && !currprefs.win32_ctrl_F11_is_quit) { #ifdef RETROPLATFORM if (rp_close ()) return -1; @@ -573,7 +574,7 @@ static int keyhack (int scancode, int pressed, int num) #endif // release mouse if TAB and ALT is pressed - if (pressed && di_keycodes[num][DIK_LALT] && scancode == DIK_TAB) { + if (pressed && (di_keycodes[num][DIK_LALT] & 1) && scancode == DIK_TAB) { disablecapture (); return -1; } @@ -588,48 +589,49 @@ static int keyhack (int scancode, int pressed, int num) //is release if (scancode == DIK_BACKSLASH) // The # key { - if (di_keycodes[num][DIK_LSHIFT] || di_keycodes[num][DIK_RSHIFT] || apostrophstate) + if ((di_keycodes[num][DIK_LSHIFT] & 1) || (di_keycodes[num][DIK_RSHIFT] & 1) || apostrophstate) { if (pressed) - { apostrophstate=1; - inputdevice_translatekeycode (num, DIK_RSHIFT, 0); - inputdevice_translatekeycode (num, DIK_LSHIFT, 0); - return 13; // the german ' key + { + apostrophstate=1; + inputdevice_translatekeycode (num, DIK_RSHIFT, 0, false); + inputdevice_translatekeycode (num, DIK_LSHIFT, 0, false); + return 13; // the german ' key } else { //best is add a real keystatecheck here but it still work so apostrophstate = 0; - inputdevice_translatekeycode (num, DIK_LALT,0); - inputdevice_translatekeycode (num, DIK_LSHIFT,0); - inputdevice_translatekeycode (num, 4, 0); // release also the # key + inputdevice_translatekeycode (num, DIK_LALT, 0, true); + inputdevice_translatekeycode (num, DIK_LSHIFT, 0, true); + inputdevice_translatekeycode (num, 4, 0, true); // release also the # key return 13; } } if (pressed) { - inputdevice_translatekeycode (num, DIK_LALT, 1); - inputdevice_translatekeycode (num, DIK_LSHIFT,1); + inputdevice_translatekeycode (num, DIK_LALT, 1, false); + inputdevice_translatekeycode (num, DIK_LSHIFT, 1, false); return 4; // the german # key } else { - inputdevice_translatekeycode (num, DIK_LALT, 0); - inputdevice_translatekeycode (num, DIK_LSHIFT, 0); + inputdevice_translatekeycode (num, DIK_LALT, 0, true); + inputdevice_translatekeycode (num, DIK_LSHIFT, 0, true); // Here is the same not nice but do the job return 4; // the german # key } } - if ((di_keycodes[num][DIK_RALT]) || (backslashstate)) { + if (((di_keycodes[num][DIK_RALT] & 1)) || (backslashstate)) { switch (scancode) { case 12: if (pressed) { backslashstate=1; - inputdevice_translatekeycode (num, DIK_RALT, 0); + inputdevice_translatekeycode (num, DIK_RALT, 0, true); return DIK_BACKSLASH; } else @@ -2544,16 +2546,26 @@ static void handle_rawinput_2 (RAWINPUT *raw) } } else { scancode = keyhack (scancode, pressed, num); - //write_log (_T("%02X %d %d\n"), scancode, pressed, isfocus ()); +#if DEBUG_SCANCODE + write_log (_T("%02X %d %d\n"), scancode, pressed, isfocus ()); +#endif if (scancode < 0) return; if (!isfocus ()) return; if (isfocus () < 2 && currprefs.input_tablet >= TABLET_MOUSEHACK && (currprefs.input_mouse_untrap & MOUSEUNTRAP_MAGIC)) return; - di_keycodes[num][scancode] = pressed; + if (pressed) { + di_keycodes[num][scancode] = 1; + } else { + if ((di_keycodes[num][scancode] & 1) && pause_emulation) { + di_keycodes[num][scancode] = 2; + } else { + di_keycodes[num][scancode] = 0; + } + } if (stopoutput == 0) { - my_kbd_handler (num, scancode, pressed); + my_kbd_handler (num, scancode, pressed, false); } } } @@ -3659,7 +3671,7 @@ int ispressed (int key) return 0; int i; for (i = 0; i < MAX_INPUT_DEVICES; i++) { - if (di_keycodes[i][key]) + if (di_keycodes[i][key] & 1) return 1; } return 0; @@ -3672,9 +3684,11 @@ static void release_keys (void) for (j = 0; j < MAX_INPUT_DEVICES; j++) { for (i = 0; i < MAX_KEYCODES; i++) { if (di_keycodes[j][i]) { - my_kbd_handler (j, i, 0); - //write_log(_T("release %d:%02x\n"), j, i); +#if DEBUG_SCANCODE + write_log(_T("release %d:%02x:%02x\n"), j, di_keycodes[j][i], i); +#endif di_keycodes[j][i] = 0; + my_kbd_handler(j, i, 0, true); } } } @@ -3799,10 +3813,10 @@ static int refresh_kb (LPDIRECTINPUTDEVICE8 lpdi, int num) kc[i] = 1; else kc[i] = 0; - if (kc[i] != di_keycodes[num][i]) { + if (kc[i] != (di_keycodes[num][i] & 1)) { write_log (_T("%d: %02X -> %d\n"), num, i, kc[i]); di_keycodes[num][i] = kc[i]; - my_kbd_handler (num, i, kc[i]); + my_kbd_handler (num, i, kc[i], true); } } } else if (hr == DIERR_INPUTLOST) { @@ -3861,7 +3875,15 @@ static void read_kb (void) scancode = keyhack (scancode, pressed, i); if (scancode < 0) continue; - di_keycodes[i][scancode] = pressed; + if (pressed) { + di_keycodes[i][scancode] = 1; + } else { + if ((di_keycodes[i][scancode] & 1) && pause_emulation) { + di_keycodes[i][scancode] = 2; + } else { + di_keycodes[i][scancode] = 0; + } + } if (istest) { if (pressed && (scancode == DIK_F12)) return; @@ -3873,7 +3895,7 @@ static void read_kb (void) } } else { if (stopoutput == 0) - my_kbd_handler (i, scancode, pressed); + my_kbd_handler (i, scancode, pressed, false); } } } else if (hr == DIERR_INPUTLOST) { diff --git a/od-win32/keyboard_win32.cpp b/od-win32/keyboard_win32.cpp index bb14661e..136595eb 100644 --- a/od-win32/keyboard_win32.cpp +++ b/od-win32/keyboard_win32.cpp @@ -387,7 +387,7 @@ static const int np[] = { DIK_NUMPAD3, 3, DIK_NUMPAD4, 4, DIK_NUMPAD5, 5, DIK_NUMPAD6, 6, DIK_NUMPAD7, 7, DIK_NUMPAD8, 8, DIK_NUMPAD9, 9, -1 }; -bool my_kbd_handler (int keyboard, int scancode, int newstate) +bool my_kbd_handler (int keyboard, int scancode, int newstate, bool alwaysrelease) { int code = 0; int scancode_new; @@ -639,7 +639,7 @@ bool my_kbd_handler (int keyboard, int scancode, int newstate) return true; } - return inputdevice_translatekeycode (keyboard, scancode, newstate) != 0; + return inputdevice_translatekeycode (keyboard, scancode, newstate, alwaysrelease) != 0; } void keyboard_settrans (void) diff --git a/od-win32/rp.cpp b/od-win32/rp.cpp index 3c727100..dfa74872 100644 --- a/od-win32/rp.cpp +++ b/od-win32/rp.cpp @@ -2075,7 +2075,7 @@ int rp_checkesc (int scancode, int pressed, int num) esctime = t + rp_rpescapeholdtime; return 1; } - my_kbd_handler (num, scancode, 1); + my_kbd_handler (num, scancode, 1, false); releasetime = 10; releasenum = num; esctime = 0; diff --git a/od-win32/win32.cpp b/od-win32/win32.cpp index 5c56f943..21563176 100644 --- a/od-win32/win32.cpp +++ b/od-win32/win32.cpp @@ -501,6 +501,7 @@ bool resumepaused (int priority) pause_emulation = 0; setsystime (); setmaintitle(hMainWnd); + wait_keyrelease(); return true; } bool setpaused (int priority) @@ -508,7 +509,6 @@ bool setpaused (int priority) //write_log (_T("pause %d (%d)\n"), priority, pause_emulation); if (pause_emulation > priority) return false; - wait_keyrelease(); pause_emulation = priority; devices_pause(); setsoundpaused ();