Support Unicode Keyboard Input

This commit is contained in:
Thomas Bernard 2018-02-15 14:46:44 +01:00
parent 689aebf264
commit 144d10b682
5 changed files with 13 additions and 5 deletions

View File

@ -97,6 +97,8 @@ GFX2_GLOBAL dword Key;
/// This is mostly used when the user enters text (filename, etc).
GFX2_GLOBAL dword Key_ANSI;
GFX2_GLOBAL dword Key_UNICODE;
// Keyboard modifiers
// (Name conflict with windows.h)
#ifdef MOD_SHIFT

View File

@ -383,6 +383,9 @@ int Handle_key_press(SDL_KeyboardEvent event)
Key = Keysym_to_keycode(event.keysym);
Key_ANSI = Keysym_to_ANSI(event.keysym);
Key_UNICODE = event.keysym.unicode;
if (Key_UNICODE == 0)
Key_UNICODE = Key_ANSI;
switch(event.keysym.sym)
{
case SDLK_RSHIFT:
@ -847,6 +850,7 @@ int Get_input(int sleep_time)
// some user input.
Flush_update();
Key_ANSI = 0;
Key_UNICODE = 0;
Key = 0;
Mouse_moved=0;
Input_new_mouse_X = Mouse_X;

View File

@ -30,8 +30,8 @@
/// This is the keyboard/mouse/joystick input polling function.
/// Returns 1 if a significant changed occurred, such as a mouse button pressed
/// or depressed, or a new keypress was in the keyboard buffer.
/// The latest input variables are held in ::Key, ::Key_ANSI, ::Mouse_X, ::Mouse_Y, ::Mouse_K.
/// Note that ::Key and ::Key_ANSI are not persistent, they will be reset to 0
/// The latest input variables are held in ::Key, ::Key_ANSI, ::Key_UNICODE, ::Mouse_X, ::Mouse_Y, ::Mouse_K.
/// Note that ::Key, ::Key_ANSI and ::Key_UNICODE are not persistent, they will be reset to 0
/// on subsequent calls to ::Get_input().
int Get_input(int sleep_time);

View File

@ -633,7 +633,7 @@ word Keysym_to_ANSI(SDL_keysym keysym)
// This part was removed from the MacOSX port, but I put it back for others
// as on Linux and Windows, it's what allows editing a text line with the keys
// SDLK_LEFT, SDLK_RIGHT, SDLK_HOME, SDLK_END etc.
#if !(defined(__macosx__) || defined(__FreeBSD__))
#if !defined(__macosx__)
if ( keysym.unicode == 0)
{
@ -722,6 +722,8 @@ word Keysym_to_ANSI(SDL_keysym keysym)
return 'º'; // º
case 0xC600:
return 'ã'; // ã
case 0x20AC:
return '\x80'; // Euro sign is 20AC in unicode, 80 in CP1252
}
// Key entre 127 et 255

View File

@ -172,7 +172,7 @@ int Valid_character(word c, int input_type)
#endif
int position;
if (c < ' ' || c > 255)
if (c < ' ')
return 0;
for (position=0; position<(long)sizeof(forbidden_char); position++)
@ -649,7 +649,7 @@ byte Readline_ex_unicode(word x_pos,word y_pos,char * str,word * str_unicode,byt
do
{
Get_input(20);
input_key=Key_ANSI;
input_key = (str_unicode == NULL) ? Key_ANSI : Key_UNICODE;
if (Mouse_K)
input_key=SDLK_RETURN;