Port Native keyboard

This commit is contained in:
NepDisk 2025-09-13 22:41:48 -04:00
parent 8348ed1c05
commit d00e674088
6 changed files with 46 additions and 2 deletions

View file

@ -677,6 +677,9 @@ static void CON_MoveConsole(void)
INT32 CON_ShiftChar(INT32 ch)
{
if (I_UseNativeKeyboard())
return ch;
if ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z'))
{
if (shiftdown ^ capslock)

View file

@ -153,6 +153,8 @@ void I_EndRead(void);
UINT32 I_GetRefreshRate(void);
boolean I_UseNativeKeyboard(void);
void I_SetBorderlessWindow(void);
#ifdef __cplusplus

View file

@ -146,6 +146,7 @@ const char *quitmsg[NUM_QUITMESSAGES];
boolean fromlevelselect = false;
boolean menu_text_input = false;
static char menu_text_input_buf[MAXSTRINGLENGTH];
static textinput_t menuinput;
@ -1634,6 +1635,7 @@ boolean M_Responder(event_t *ev)
if (M_TextInputHandle(&menuinput, ch))
{
menu_text_input = true;
S_StartSound(NULL, sfx_menu1); // Tails
CV_Set(item->cvar, menuinput.buffer);
return true;

View file

@ -490,6 +490,8 @@ UINT16 M_GetColorAfter(UINT16 color);
void M_InitPlayerSetupColors(void);
void M_FreePlayerSetupColors(void);
extern boolean menu_text_input;
#ifdef __cplusplus
} // extern "C"
#endif

View file

@ -382,7 +382,7 @@ static boolean M_TextInputHandleBase(textinput_t *input, INT32 key, boolean emot
key = '/';
// same capslock code as hu_stuff.c's HU_responder. Check there for details.
key = /*cv_keyboardlayout.value == 3 ? CON_ShitAndAltGrChar(key) : */CON_ShiftChar(key);
key = CON_ShiftChar(key);
// enter a char into the command prompt
if (key < 32 || key > 127)

View file

@ -501,6 +501,40 @@ static INT32 Impl_SDL_Scancode_To_Keycode(SDL_Scancode code)
return 0;
}
boolean I_UseNativeKeyboard(void)
{
return (chat_on || CON_Ready() || (menu_text_input && menustack[0]));
}
// Get the equivalent ASCII (Unicode?) character for a keypress.
static INT32 GetTypedChar(SDL_Keysym keysym)
{
SDL_Event next_event;
SDL_Keycode keycode = keysym.sym;
SDL_Scancode scancode = keysym.scancode;
const boolean Text_Input_Only = I_UseNativeKeyboard(); // only use this this if on chat or console or the current menu wants inputs from us (except if its the control setup menu ig)
// Special cases, where we always return a fixed value.
switch (keycode)
{
case SDLK_BACKSPACE: return KEY_BACKSPACE;
case SDLK_RETURN: return KEY_ENTER;
default:
break;
}
if (Text_Input_Only)
{
if (SDL_PeepEvents(&next_event, 1, SDL_PEEKEVENT, SDL_FIRSTEVENT, SDL_LASTEVENT) == 1 && next_event.type == SDL_TEXTINPUT)
{
if (next_event.text.text[1] == '\0') // limit to ASCII
return next_event.text.text[0];
}
}
return Impl_SDL_Scancode_To_Keycode(scancode); // fallback
}
static boolean IgnoreMouse(void)
{
if (cv_alwaysgrabmouse.value)
@ -699,7 +733,8 @@ static void Impl_HandleKeyboardEvent(SDL_KeyboardEvent evt, Uint32 type)
{
return;
}
event.data1 = Impl_SDL_Scancode_To_Keycode(evt.keysym.scancode);
event.data1 = GetTypedChar(evt.keysym);
if (event.data1) D_PostEvent(&event);
}