@@ -162,6 +162,15 @@ static ImGuiKey TranslateKeyCode( const char* code )
162162 return ImGuiKey_None;
163163}
164164
165+ static void UpdateKeyModifiers ( const EmscriptenKeyboardEvent* e )
166+ {
167+ ImGuiIO& io = ImGui::GetIO ();
168+ io.AddKeyEvent ( ImGuiMod_Ctrl, e->ctrlKey );
169+ io.AddKeyEvent ( ImGuiMod_Shift, e->shiftKey );
170+ io.AddKeyEvent ( ImGuiMod_Alt, e->altKey );
171+ io.AddKeyEvent ( ImGuiMod_Super, e->metaKey );
172+ }
173+
165174Backend::Backend ( const char * title, const std::function<void ()>& redraw, const std::function<void(float )>& scaleChanged, const std::function<int(void )>& isBusy, RunQueue* mainThreadTasks )
166175{
167176 constexpr EGLint eglConfigAttrib[] = {
@@ -243,13 +252,15 @@ Backend::Backend( const char* title, const std::function<void()>& redraw, const
243252 return EM_TRUE ;
244253 } );
245254 emscripten_set_keydown_callback ( EMSCRIPTEN_EVENT_TARGET_WINDOW , nullptr , EM_TRUE , [] ( int , const EmscriptenKeyboardEvent* e, void * ) -> EM_BOOL {
255+ UpdateKeyModifiers ( e );
246256 const auto code = TranslateKeyCode ( e->code );
247257 if ( code == ImGuiKey_None ) return EM_FALSE ;
248258 ImGui::GetIO ().AddKeyEvent ( code, true );
249259 if ( e->key [0 ] && !e->key [1 ] && !e->ctrlKey && !e->metaKey ) ImGui::GetIO ().AddInputCharacter ( *e->key );
250260 return EM_TRUE ;
251261 } );
252262 emscripten_set_keyup_callback ( EMSCRIPTEN_EVENT_TARGET_WINDOW , nullptr , EM_TRUE , [] ( int , const EmscriptenKeyboardEvent* e, void * ) -> EM_BOOL {
263+ UpdateKeyModifiers ( e );
253264 const auto code = TranslateKeyCode ( e->code );
254265 if ( code == ImGuiKey_None ) return EM_FALSE ;
255266 ImGui::GetIO ().AddKeyEvent ( code, false );
0 commit comments