Using the previous code with newer SDL versions on Android, when
entering text using the screen keyboard, all keys were processed
twice, because of different handling of text events and modifier
keys in recent SDL versions.
The new, more generic approach should work for all SDL versions
on all platforms.
-static boolean checkTextInputKeyModState(void)
+static boolean checkTextInputKey(Key key)
- // when playing, only handle raw key events and ignore text input
- if (game_status == GAME_MODE_PLAYING)
- return FALSE;
-
- return ((GetKeyModState() & KMOD_TextInput) != KMOD_None);
+ return (textinput_status && KSYM_PRINTABLE(key));
}
void HandleTextEvent(TextEvent *event)
}
void HandleTextEvent(TextEvent *event)
GetKeyModState());
#endif
GetKeyModState());
#endif
-#if !defined(HAS_SCREEN_KEYBOARD)
- // non-mobile devices: only handle key input with modifier keys pressed here
- // (every other key input is handled directly as physical key input event)
- if (!checkTextInputKeyModState())
- return;
-#endif
-
- // process text input as "classic" (with uppercase etc.) key input event
- HandleKey(key, KEY_PRESSED);
- HandleKey(key, KEY_RELEASED);
+ if (checkTextInputKey(key))
+ {
+ // process printable keys (with uppercase etc.) in text input mode
+ HandleKey(key, KEY_PRESSED);
+ HandleKey(key, KEY_RELEASED);
+ }
}
void HandlePauseResumeEvent(PauseResumeEvent *event)
}
void HandlePauseResumeEvent(PauseResumeEvent *event)
HandleKeyModState(keymod, key_status);
HandleKeyModState(keymod, key_status);
- // only handle raw key input without text modifier keys pressed
- if (!checkTextInputKeyModState())
+ // process all keys if not in text input mode or if non-printable keys
+ if (!checkTextInputKey(key))
HandleKey(key, key_status);
}
HandleKey(key, key_status);
}
#define KSYM_FKEY_LAST KSYM_F12
#define KSYM_NUM_FKEYS (KSYM_FKEY_LAST - KSYM_FKEY_FIRST + 1)
#define KSYM_FKEY_LAST KSYM_F12
#define KSYM_NUM_FKEYS (KSYM_FKEY_LAST - KSYM_FKEY_FIRST + 1)
+#define KSYM_PRINTABLE(k) (((k) >= KSYM_space && \
+ (k) <= KSYM_z) || \
+ (k) == KSYM_Adiaeresis || \
+ (k) == KSYM_Odiaeresis || \
+ (k) == KSYM_Udiaeresis || \
+ (k) == KSYM_adiaeresis || \
+ (k) == KSYM_odiaeresis || \
+ (k) == KSYM_udiaeresis)
+
#define KMOD_None KMOD_NONE
#define KMOD_Shift_L KMOD_LSHIFT
#define KMOD_Shift_R KMOD_RSHIFT
#define KMOD_None KMOD_NONE
#define KMOD_Shift_L KMOD_LSHIFT
#define KMOD_Shift_R KMOD_RSHIFT
-#define KMOD_TextInput (KMOD_Shift | KMOD_Alt_R)
-
// SDL function definitions
boolean SDLSetNativeSurface(SDL_Surface **);
// SDL function definitions
boolean SDLSetNativeSurface(SDL_Surface **);
boolean motion_status = FALSE;
int wheel_steps = DEFAULT_WHEEL_STEPS;
boolean keyrepeat_status = TRUE;
boolean motion_status = FALSE;
int wheel_steps = DEFAULT_WHEEL_STEPS;
boolean keyrepeat_status = TRUE;
+boolean textinput_status = FALSE;
int redraw_mask = REDRAW_NONE;
int redraw_mask = REDRAW_NONE;
void StartTextInput(int x, int y, int width, int height)
{
void StartTextInput(int x, int y, int width, int height)
{
+ textinput_status = TRUE;
+
#if defined(HAS_SCREEN_KEYBOARD)
SDL_StartTextInput();
#if defined(HAS_SCREEN_KEYBOARD)
SDL_StartTextInput();
void StopTextInput(void)
{
void StopTextInput(void)
{
+ textinput_status = FALSE;
+
#if defined(HAS_SCREEN_KEYBOARD)
SDL_StopTextInput();
#if defined(HAS_SCREEN_KEYBOARD)
SDL_StopTextInput();
extern boolean motion_status;
extern int wheel_steps;
extern boolean keyrepeat_status;
extern boolean motion_status;
extern int wheel_steps;
extern boolean keyrepeat_status;
+extern boolean textinput_status;