diff --git a/src/openrct2-ui/input/input.c b/src/openrct2-ui/input/input.c index 088ebb1113..ae363ec8f6 100644 --- a/src/openrct2-ui/input/input.c +++ b/src/openrct2-ui/input/input.c @@ -99,6 +99,19 @@ static void game_handle_key_scroll() } } +static sint32 input_scancode_to_rct_keycode(sint32 sdl_key) +{ + char keycode = (char)SDL_GetKeyFromScancode((SDL_Scancode)sdl_key); + + // Until we reshuffle the text files to use the new positions + // this will suffice to move the majority to the correct positions. + // Note any special buttons PgUp PgDwn are mapped wrong. + if (keycode >= 'a' && keycode <= 'z') + keycode = toupper(keycode); + + return keycode; +} + void input_handle_keyboard(bool isTitle) { if (gOpenRCT2Headless) { @@ -162,7 +175,8 @@ void input_handle_keyboard(bool isTitle) rct_window * w = window_find_by_class(WC_TEXTINPUT); if (w != NULL) { - window_text_input_key(w, key); + char keychar = input_scancode_to_rct_keycode(key & 0xFF); + window_text_input_key(w, keychar); } else if (!gUsingWidgetTextBox) { w = window_find_by_class(WC_CHANGE_KEYBOARD_SHORTCUT); if (w != NULL) { diff --git a/src/openrct2/interface/window.h b/src/openrct2/interface/window.h index 2d634391ee..7e3d81af0b 100644 --- a/src/openrct2/interface/window.h +++ b/src/openrct2/interface/window.h @@ -656,7 +656,7 @@ void window_zoom_out(rct_window *w, bool atCursor); void main_window_zoom(bool zoomIn, bool atCursor); void window_show_textinput(rct_window *w, rct_widgetindex widgetIndex, uint16 title, uint16 text, sint32 value); -void window_text_input_key(rct_window* w, sint32 key); +void window_text_input_key(rct_window* w, char keychar); void window_draw_all(rct_drawpixelinfo *dpi, sint16 left, sint16 top, sint16 right, sint16 bottom); void window_draw(rct_drawpixelinfo *dpi, rct_window *w, sint32 left, sint32 top, sint32 right, sint32 bottom); diff --git a/src/openrct2/platform/platform.h b/src/openrct2/platform/platform.h index ccb90bd2c0..01e402b095 100644 --- a/src/openrct2/platform/platform.h +++ b/src/openrct2/platform/platform.h @@ -107,7 +107,6 @@ void platform_free(); void platform_update_palette(const uint8 *colours, sint32 start_index, sint32 num_colours); void platform_toggle_windowed_mode(); void platform_refresh_video(); -sint32 platform_scancode_to_rct_keycode(sint32 sdl_key); void platform_get_date_utc(rct2_date *out_date); void platform_get_time_utc(rct2_time *out_time); void platform_get_date_local(rct2_date *out_date); diff --git a/src/openrct2/platform/posix.c b/src/openrct2/platform/posix.c index 4046ff8a11..563c78366b 100644 --- a/src/openrct2/platform/posix.c +++ b/src/openrct2/platform/posix.c @@ -25,7 +25,6 @@ #include #include #include -#include #include "../config/Config.h" #include "../localisation/date.h" #include "../localisation/language.h" diff --git a/src/openrct2/platform/shared.c b/src/openrct2/platform/shared.c index 6cbcd3856d..98f7f35d90 100644 --- a/src/openrct2/platform/shared.c +++ b/src/openrct2/platform/shared.c @@ -135,19 +135,6 @@ void platform_init() gPalette[255].blue = 255; } -sint32 platform_scancode_to_rct_keycode(sint32 sdl_key) -{ - char keycode = (char)SDL_GetKeyFromScancode((SDL_Scancode)sdl_key); - - // Until we reshuffle the text files to use the new positions - // this will suffice to move the majority to the correct positions. - // Note any special buttons PgUp PgDwn are mapped wrong. - if (keycode >= 'a' && keycode <= 'z') - keycode = toupper(keycode); - - return keycode; -} - void platform_free() { // free(gKeysPressed); diff --git a/src/openrct2/windows/text_input.c b/src/openrct2/windows/text_input.c index 758010c78d..09f0477dd2 100644 --- a/src/openrct2/windows/text_input.c +++ b/src/openrct2/windows/text_input.c @@ -331,12 +331,10 @@ static void window_text_input_paint(rct_window *w, rct_drawpixelinfo *dpi) } } -void window_text_input_key(rct_window* w, sint32 key) +void window_text_input_key(rct_window* w, char keychar) { - char new_char = platform_scancode_to_rct_keycode(0xFF&key); - // If the return button is pressed stop text input - if (new_char == '\r'){ + if (keychar == '\r'){ context_stop_text_input(); window_close(w); rct_window* calling_w = window_find_by_number(calling_class, calling_number);