Hello guys,
I am trying to make an SDL app of mine working when typing texts in other encodings than the English ones. For example, I want to type in Greek, but when I switch my locale the SDL_TEXTINPUT event is not triggered at all.
I have a small demo that shows the problem
#include <SDL.h> #include <stdio.h> int main(int argc, char* argv[]) { if (SDL_Init(SDL_INIT_VIDEO) < 0) { printf("SDL could not initialize! SDL_Error: %s\n", SDL_GetError()); return 1; } SDL_Window* window = SDL_CreateWindow("SDL Unicode Example", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 640, 480, SDL_WINDOW_SHOWN); if (window == NULL) { printf("Window could not be created! SDL_Error: %s\n", SDL_GetError()); return 1; } SDL_Renderer* renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED); SDL_Event e; int quit = 0; while (!quit) { while (SDL_PollEvent(&e) != 0) { if (e.type == SDL_QUIT) { quit = 1; } else if (e.type == SDL_TEXTINPUT) { // Handle Unicode characters printf("Text input: %s\n", e.text.text); } } } SDL_DestroyRenderer(renderer); SDL_DestroyWindow(window); SDL_Quit(); return 0; }
You can compile it with something like:
gcc -o sdl_textinput sdl_textinput.c -I/sdk/local/newlib/include/SDL2 -lSDL2
Does anyone know if that's the case and if there is a workaround? Is this something that is happening in our SDL port, or is it a problem of the keymap?
compiled here and in my spanish keyboard the Ñ (n with tilde) doesn't work ¿:-/, maybe it only "acts" on "ASCII" keystrokes.
#SDL_TextInput
Text input: u
Text input: u
Text input: i
Text input: i
<here y press Ñ (n with tilde ñ) but don't get any output>
Text input: .
Text input: .
Text input: .
Text input: ,
Text input: ,
Text input: ,
Text input: -
Text input: -
Text input: l
Text input: l
Text input: l
AOS4.1/SAM460ex/PPC460EX-1155MHZ/2048MB/RadeonHD6570/SSD120GB/DVDRW :-P
@jabirulo
Thank you for testing it. I opened an issue at https://github.com/AmigaPorts/SDL-2.0/issues/73
BTW no idea if useful, but I have a string to file as utf-8 using codeset_lib:
AOS4.1/SAM460ex/PPC460EX-1155MHZ/2048MB/RadeonHD6570/SSD120GB/DVDRW :-P