mirror of
https://github.com/ocornut/imgui.git
synced 2026-01-11 00:04:24 +00:00
add special handling for modifier keys to also generate modifier key events
This commit is contained in:
parent
bee91678d6
commit
8ecea4d569
1 changed files with 43 additions and 4 deletions
|
|
@ -451,16 +451,33 @@ void ImGui_ImplEmscripten_Init() {
|
||||||
auto const key{translate_key(key_event->code)};
|
auto const key{translate_key(key_event->code)};
|
||||||
auto &imgui_io{ImGui::GetIO()};
|
auto &imgui_io{ImGui::GetIO()};
|
||||||
imgui_io.AddKeyEvent(key, true);
|
imgui_io.AddKeyEvent(key, true);
|
||||||
|
switch(key) { // special cases for certain key events
|
||||||
switch(key) { // special cases for certain key events that need to be consumed to prevent unwanted behaviour
|
case ImGuiKey_LeftCtrl: // additional events for modifier keys
|
||||||
|
case ImGuiKey_RightCtrl:
|
||||||
|
imgui_io.AddKeyEvent(ImGuiMod_Ctrl, true);
|
||||||
|
break;
|
||||||
|
case ImGuiKey_LeftShift:
|
||||||
|
case ImGuiKey_RightShift:
|
||||||
|
imgui_io.AddKeyEvent(ImGuiMod_Shift, true);
|
||||||
|
break;
|
||||||
|
case ImGuiKey_LeftAlt:
|
||||||
|
case ImGuiKey_RightAlt:
|
||||||
|
imgui_io.AddKeyEvent(ImGuiMod_Alt, true);
|
||||||
|
break;
|
||||||
|
case ImGuiKey_LeftSuper:
|
||||||
|
case ImGuiKey_RightSuper:
|
||||||
|
imgui_io.AddKeyEvent(ImGuiMod_Super, true);
|
||||||
|
break;
|
||||||
|
// TODO: case ImGuiKey_Menu: do we want to do anything with this?
|
||||||
case ImGuiKey_Tab: // consuming tab prevents the user tabbing to other parts of the browser interface outside the window content
|
case ImGuiKey_Tab: // consuming tab prevents the user tabbing to other parts of the browser interface outside the window content
|
||||||
return imgui_io.WantCaptureKeyboard; // the event was consumed only if imgui wants to capture the keyboard
|
return imgui_io.WantCaptureKeyboard; // the event was consumed only if imgui wants to capture the keyboard
|
||||||
case ImGuiKey_Enter: // consuming enter prevents the word "Enter" appearing in text input via the keypress callback
|
case ImGuiKey_Enter: // consuming enter prevents the word "Enter" appearing in text input via the keypress callback
|
||||||
case ImGuiKey_Delete: // consuming enter prevents the word "Delete" appearing in text input via the keypress callback
|
case ImGuiKey_Delete: // consuming enter prevents the word "Delete" appearing in text input via the keypress callback
|
||||||
return imgui_io.WantTextInput; // the event was consumed only if we're currently accepting text input
|
return imgui_io.WantTextInput; // the event was consumed only if we're currently accepting text input
|
||||||
default:
|
default:
|
||||||
return false; // the event was not consumed
|
break;
|
||||||
}
|
}
|
||||||
|
return false; // if no special handling, the event was not consumed
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
emscripten_set_keyup_callback(
|
emscripten_set_keyup_callback(
|
||||||
|
|
@ -468,7 +485,29 @@ void ImGui_ImplEmscripten_Init() {
|
||||||
nullptr, // userData
|
nullptr, // userData
|
||||||
false, // useCapture
|
false, // useCapture
|
||||||
[](int /*event_type*/, EmscriptenKeyboardEvent const *key_event, void */*data*/){ // callback, event_type == EMSCRIPTEN_EVENT_KEYUP
|
[](int /*event_type*/, EmscriptenKeyboardEvent const *key_event, void */*data*/){ // callback, event_type == EMSCRIPTEN_EVENT_KEYUP
|
||||||
ImGui::GetIO().AddKeyEvent(translate_key(key_event->code), false);
|
auto const key{translate_key(key_event->code)};
|
||||||
|
auto &imgui_io{ImGui::GetIO()};
|
||||||
|
imgui_io.AddKeyEvent(key, false);
|
||||||
|
switch(key) { // special cases for certain key events
|
||||||
|
case ImGuiKey_LeftCtrl: // additional events for modifier keys
|
||||||
|
case ImGuiKey_RightCtrl:
|
||||||
|
imgui_io.AddKeyEvent(ImGuiMod_Ctrl, false);
|
||||||
|
break;
|
||||||
|
case ImGuiKey_LeftShift:
|
||||||
|
case ImGuiKey_RightShift:
|
||||||
|
imgui_io.AddKeyEvent(ImGuiMod_Shift, false);
|
||||||
|
break;
|
||||||
|
case ImGuiKey_LeftAlt:
|
||||||
|
case ImGuiKey_RightAlt:
|
||||||
|
imgui_io.AddKeyEvent(ImGuiMod_Alt, false);
|
||||||
|
break;
|
||||||
|
case ImGuiKey_LeftSuper:
|
||||||
|
case ImGuiKey_RightSuper:
|
||||||
|
imgui_io.AddKeyEvent(ImGuiMod_Super, false);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
return false; // the event was not consumed
|
return false; // the event was not consumed
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue