If you start the program with the English layout, then the program does not change the layout when you press the keyboard layout change. If you run with the Russian layout, it does not change to English. Apparently the program catches all keystrokes. And then what to do? I need to switch the layout.

#include <stdio.h> #include "gl.h" #include "ft.h" #include "sh.h" #include "font.h" #include "global.h" #include "shaders.h" #include "button.h" #include "color_theme.h" #include "panel_ipsi.h" int color; struct file_manager_item *fmi; struct panel_ipsi *pi; int click; int motion; int x; int y; int key; wchar_t buf[4096]; int ibuf; int thread ( void *data ) { SDL_Event event; while ( SDL_WaitEvent ( &event ) ) { switch ( event.type ) { case SDL_KEYDOWN: key = event.key.keysym.sym; if ( key == 0x40000000 ) continue; if ( key == '\b' ) { buf[--ibuf] = 0; continue; } printf ( "%x\n", key ); // mbstowcs ( &buf[ibuf++], key, 1 ); buf[ibuf++] = key; break; case SDL_MOUSEBUTTONDOWN: { click = 0; } break; case SDL_MOUSEBUTTONUP: { x = event.button.x; y = global.height - event.button.y; click = 1; } break; case SDL_MOUSEMOTION: { motion = click ? 0 : 1; } break; } } return 0; } int main ( int argc, char **argv ) { SDL_Init ( SDL_INIT_TIMER | SDL_INIT_VIDEO | SDL_INIT_EVENTS ); SDL_DisplayMode mode; #if 1 SDL_GL_SetAttribute ( SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES ); SDL_GL_SetAttribute ( SDL_GL_CONTEXT_MAJOR_VERSION, 3 ); SDL_GL_SetAttribute ( SDL_GL_CONTEXT_MINOR_VERSION, 0 ); #endif SDL_GetCurrentDisplayMode ( 0, &mode ); int width = mode.w; int height = mode.h; global.width = width; global.height = height; #if 1 SDL_GL_SetAttribute ( SDL_GL_ACCELERATED_VISUAL, 1 ); SDL_GL_SetAttribute ( SDL_GL_DOUBLEBUFFER, 1 ); SDL_GL_SetAttribute ( SDL_GL_DEPTH_SIZE, 24 ); #endif int flags = 0; flags = SDL_WINDOW_OPENGL | SDL_WINDOW_FULLSCREEN; #if defined ( __ANDROID__ ) flags |= SDL_WINDOW_FULLSCREEN; #endif SDL_Window *window = SDL_CreateWindow ( "ipsi", 0, 0, width, height, flags ); // SDL_SetWindowDisplayMode ( window, &mode ); SDL_GLContext glc; glc = SDL_GL_CreateContext ( window ); SDL_GL_MakeCurrent ( window, glc ); glViewport ( 0, 0, width, height ); glLoadIdentity ( ); glMatrixMode ( GL_MODELVIEW ); glEnable ( GL_BLEND ); glBlendFunc ( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); glClearColor ( 1, 1, 1, 1 ); FT_Library ft_library; shaders_init ( ); global.ft_library = &ft_library; FT_Init_FreeType ( &ft_library ); char *working_dir = getcwd ( NULL, 0 ); int len_working_dir = strlen ( working_dir ); global.root = calloc ( len_working_dir + 1, 1 ); strncpy ( global.root, working_dir, len_working_dir ); /* цвет темы */ color = BLUE_WHITE; global.color = color; SDL_CreateThread ( thread, "wait", NULL ); pi = calloc ( 1, sizeof ( struct panel_ipsi ) ); panel_ipsi_init ( pi ); panel_ipsi_set_color ( pi, color_theme[color].fill, color_theme[color].fill2, color_theme[color].border, color_theme[color].border2, color_theme[color].text, color_theme[color].text2, color_theme[color].select_icon, color_theme[color].select_item, color_theme[color].free_space ); struct font *f = calloc ( 1, sizeof ( struct font ) ); font_init ( f, "assets/anonymous.ttf" ); font_set_pos ( f, 100, 100 ); while ( 1 ) { const Uint8 *state = SDL_GetKeyboardState ( NULL ); if ( state [ SDL_SCANCODE_Q ] ) { SDL_Quit ( ); exit ( EXIT_SUCCESS ); } glClear ( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); if ( click ) { panel_ipsi_check_coord ( pi, x, y ); click = 0; } if ( key ) { font_free_texture ( f ); font_set_text ( f, &buf[0], 21, 1, 1, 4, 0x000000 ); key = 0; } font_render ( f ); panel_ipsi_render ( pi ); SDL_GL_SwapWindow ( window ); SDL_Delay ( 1 ); } } 

I tried using SDL_TEXTINPUT instead of SDL_KEYDOWN . Now the layout is changing normally, but still something does not work:

 wchar_t buf[4096]; // ... case SDL_TEXTINPUT: se = &event.text.text[0]; printf ( "%s\n", se ); ret = mbstowcs ( &buf[ibuf++], se, strlen ( se ) ); if ( ret == -1 ) { perror ( "mbstowcs" ); } key = 1; break; 

Since the program works in Linux, the default encoding is utf-8. When I use the mbstowcs function, this error mbstowcs: Invalid or incomplete multibyte or wide character is displayed , and I don’t know what to do with it.

  • I'm changing normally ... The code in the studio. - HolyBlackCat 8:32 pm
  • @HolyBlackCat, full screen? - xverizex 8:33
  • @HolyBlackCat, there is the line if key == 0x4000000, it is alt pressed, my layout is switched through the right alt. - xverizex 8:36 pm
  • one
    Yes, and in full screen. But I use SDL_TEXTINPUT instead of SDL_KEYDOWN . Try this event. - HolyBlackCat 9:10 pm
  • one
    @HolyBlackCat everything works, I added setlocale and it all worked, thanks for your time. - xverizex 8:43 pm

0