MCPcopy Create free account
hub / github.com/Aegel5/SimpleSwitcher / UpdateKeyboardInputs

Method UpdateKeyboardInputs

imgui_tiny_app/imgui/imgui.cpp:10732–10797  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

10730}
10731
10732static void ImGui::UpdateKeyboardInputs()
10733{
10734 ImGuiContext& g = *GImGui;
10735 ImGuiIO& io = g.IO;
10736
10737 if (io.ConfigFlags & ImGuiConfigFlags_NoKeyboard)
10738 io.ClearInputKeys();
10739
10740 // Update aliases
10741 for (int n = 0; n < ImGuiMouseButton_COUNT; n++)
10742 UpdateAliasKey(MouseButtonToKey(n), io.MouseDown[n], io.MouseDown[n] ? 1.0f : 0.0f);
10743 UpdateAliasKey(ImGuiKey_MouseWheelX, io.MouseWheelH != 0.0f, io.MouseWheelH);
10744 UpdateAliasKey(ImGuiKey_MouseWheelY, io.MouseWheel != 0.0f, io.MouseWheel);
10745
10746 // Synchronize io.KeyMods and io.KeyCtrl/io.KeyShift/etc. values.
10747 // - New backends (1.87+): send io.AddKeyEvent(ImGuiMod_XXX) -> -> (here) deriving io.KeyMods + io.KeyXXX from key array.
10748 // - Legacy backends: set io.KeyXXX bools -> (above) set key array from io.KeyXXX -> (here) deriving io.KeyMods + io.KeyXXX from key array.
10749 // So with legacy backends the 4 values will do a unnecessary back-and-forth but it makes the code simpler and future facing.
10750 const ImGuiKeyChord prev_key_mods = io.KeyMods;
10751 io.KeyMods = GetMergedModsFromKeys();
10752 io.KeyCtrl = (io.KeyMods & ImGuiMod_Ctrl) != 0;
10753 io.KeyShift = (io.KeyMods & ImGuiMod_Shift) != 0;
10754 io.KeyAlt = (io.KeyMods & ImGuiMod_Alt) != 0;
10755 io.KeySuper = (io.KeyMods & ImGuiMod_Super) != 0;
10756 if (prev_key_mods != io.KeyMods)
10757 g.LastKeyModsChangeTime = g.Time;
10758 if (prev_key_mods != io.KeyMods && prev_key_mods == 0)
10759 g.LastKeyModsChangeFromNoneTime = g.Time;
10760
10761 // Clear gamepad data if disabled
10762 if ((io.BackendFlags & ImGuiBackendFlags_HasGamepad) == 0)
10763 for (int key = ImGuiKey_Gamepad_BEGIN; key < ImGuiKey_Gamepad_END; key++)
10764 {
10765 io.KeysData[key - ImGuiKey_NamedKey_BEGIN].Down = false;
10766 io.KeysData[key - ImGuiKey_NamedKey_BEGIN].AnalogValue = 0.0f;
10767 }
10768
10769 // Update keys
10770 for (int key = ImGuiKey_NamedKey_BEGIN; key < ImGuiKey_NamedKey_END; key++)
10771 {
10772 ImGuiKeyData* key_data = &io.KeysData[key - ImGuiKey_NamedKey_BEGIN];
10773 key_data->DownDurationPrev = key_data->DownDuration;
10774 key_data->DownDuration = key_data->Down ? (key_data->DownDuration < 0.0f ? 0.0f : key_data->DownDuration + io.DeltaTime) : -1.0f;
10775 if (key_data->DownDuration == 0.0f)
10776 {
10777 if (IsKeyboardKey((ImGuiKey)key))
10778 g.LastKeyboardKeyPressTime = g.Time;
10779 else if (key == ImGuiKey_ReservedForModCtrl || key == ImGuiKey_ReservedForModShift || key == ImGuiKey_ReservedForModAlt || key == ImGuiKey_ReservedForModSuper)
10780 g.LastKeyboardKeyPressTime = g.Time;
10781 }
10782 }
10783
10784 // Update keys/input owner (named keys only): one entry per key
10785 for (ImGuiKey key = ImGuiKey_NamedKey_BEGIN; key < ImGuiKey_NamedKey_END; key = (ImGuiKey)(key + 1))
10786 {
10787 ImGuiKeyData* key_data = &io.KeysData[key - ImGuiKey_NamedKey_BEGIN];
10788 ImGuiKeyOwnerData* owner_data = &g.KeysOwnerData[key - ImGuiKey_NamedKey_BEGIN];
10789 owner_data->OwnerCurr = owner_data->OwnerNext;

Callers

nothing calls this directly

Calls 5

UpdateAliasKeyFunction · 0.85
MouseButtonToKeyFunction · 0.85
GetMergedModsFromKeysFunction · 0.85
IsKeyboardKeyFunction · 0.85
ClearInputKeysMethod · 0.80

Tested by

no test coverage detected