this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

SDL: don't ignore briefly pressed keys (#2553)

Some keyboards send KEY_DOWN/KEY_UP immediately in
sequence to support things like dual-purpose keys.
This change updates the SDL key handler to detect
when a key is pressed and released within a single
frame, and to propagate that key's state as down
for the duration of the frame, rather than just
drop the event entirely.

authored by

dharrington and committed by
GitHub
909f1707 d71fd219

+18 -4
+18 -4
src/system/sdl/main.c
··· 143 143 struct 144 144 { 145 145 bool state[tic_keys_count]; 146 + bool pressed[tic_keys_count]; 146 147 char text; 147 148 148 149 #if defined(TOUCH_INPUT_SUPPORT) ··· 710 711 711 712 for(s32 i = 0, c = 0; i < COUNT_OF(platform.keyboard.state) && c < TIC80_KEY_BUFFER; i++) 712 713 if(platform.keyboard.state[i] 714 + // Some programmable keyboards will send key down and up events immediately. 715 + // If the key was pressed and released in the same frame, report it as 716 + // down for this frame so that it isn't missed. Lying about the key being 717 + // currently down is the only way to communicate a key press without 718 + // adding keyboard events to tic80_input. 719 + || platform.keyboard.pressed[i] 713 720 #if defined(TOUCH_INPUT_SUPPORT) 714 721 || platform.keyboard.touch.state[i] 715 722 #endif ··· 724 731 SDL_StartTextInput(); 725 732 } 726 733 #endif 734 + 735 + for(s32 i = 0, c = 0; i < COUNT_OF(platform.keyboard.state) && c < TIC80_KEY_BUFFER; i++) { 736 + platform.keyboard.pressed[i] = false; 737 + } 727 738 } 728 739 729 740 #if defined(TOUCH_INPUT_SUPPORT) ··· 1015 1026 #include "keycodes.inl" 1016 1027 }; 1017 1028 1018 - static void handleKeydown(SDL_Keycode keycode, bool down, bool* state) 1029 + static void handleKeydown(SDL_Keycode keycode, bool down, bool* state, bool* pressed) 1019 1030 { 1020 1031 for(tic_key i = 0; i < COUNT_OF(KeyboardCodes); i++) 1021 1032 { 1022 1033 if(KeyboardCodes[i] == keycode) 1023 1034 { 1035 + if (down && pressed) { 1036 + pressed[i] = true; 1037 + } 1024 1038 state[i] = down; 1025 1039 break; 1026 1040 } ··· 1155 1169 1156 1170 #if defined(TOUCH_INPUT_SUPPORT) 1157 1171 platform.keyboard.touch.useText = false; 1158 - handleKeydown(event.key.keysym.sym, true, platform.keyboard.touch.state); 1172 + handleKeydown(event.key.keysym.sym, true, platform.keyboard.touch.state, NULL); 1159 1173 1160 1174 if(event.key.keysym.sym != SDLK_AC_BACK) 1161 1175 if(!SDL_IsTextInputActive()) 1162 1176 SDL_StartTextInput(); 1163 1177 #endif 1164 1178 1165 - handleKeydown(event.key.keysym.sym, true, platform.keyboard.state); 1179 + handleKeydown(event.key.keysym.sym, true, platform.keyboard.state, platform.keyboard.pressed); 1166 1180 break; 1167 1181 case SDL_KEYUP: 1168 - handleKeydown(event.key.keysym.sym, false, platform.keyboard.state); 1182 + handleKeydown(event.key.keysym.sym, false, platform.keyboard.state, platform.keyboard.pressed); 1169 1183 break; 1170 1184 case SDL_TEXTINPUT: 1171 1185 if(strlen(event.text.text) == 1)