MCPcopy Create free account
hub / github.com/Overload-Technologies/Overload / AddKeyAnalogEvent

Method AddKeyAnalogEvent

Dependencies/ImGui/src/imgui.cpp:1683–1721  ·  view source on GitHub ↗

Queue a new key down/up event. - ImGuiKey key: Translated key (as in, generally ImGuiKey_A matches the key end-user would use to emit an 'A' character) - bool down: Is the key down? use false to signify a key release. - float analog_value: 0.0f..1.0f IMPORTANT: THIS FUNCTION AND OTHER "ADD" GRABS THE CONTEXT FROM OUR INSTANCE. WE NEED TO ENSURE THAT ALL FUNCTION CALLS ARE FULFILLING

Source from the content-addressed store, hash-verified

1681// IMPORTANT: THIS FUNCTION AND OTHER "ADD" GRABS THE CONTEXT FROM OUR INSTANCE.
1682// WE NEED TO ENSURE THAT ALL FUNCTION CALLS ARE FULFILLING THIS, WHICH IS WHY GetKeyData() HAS AN EXPLICIT CONTEXT.
1683void ImGuiIO::AddKeyAnalogEvent(ImGuiKey key, bool down, float analog_value)
1684{
1685 //if (e->Down) { IMGUI_DEBUG_LOG_IO("AddKeyEvent() Key='%s' %d, NativeKeycode = %d, NativeScancode = %d\n", ImGui::GetKeyName(e->Key), e->Down, e->NativeKeycode, e->NativeScancode); }
1686 IM_ASSERT(Ctx != NULL);
1687 if (key == ImGuiKey_None || !AppAcceptingEvents)
1688 return;
1689 ImGuiContext& g = *Ctx;
1690 IM_ASSERT(ImGui::IsNamedKeyOrMod(key)); // Backend needs to pass a valid ImGuiKey_ constant. 0..511 values are legacy native key codes which are not accepted by this API.
1691 IM_ASSERT(ImGui::IsAliasKey(key) == false); // Backend cannot submit ImGuiKey_MouseXXX values they are automatically inferred from AddMouseXXX() events.
1692
1693 // MacOS: swap Cmd(Super) and Ctrl
1694 if (g.IO.ConfigMacOSXBehaviors)
1695 {
1696 if (key == ImGuiMod_Super) { key = ImGuiMod_Ctrl; }
1697 else if (key == ImGuiMod_Ctrl) { key = ImGuiMod_Super; }
1698 else if (key == ImGuiKey_LeftSuper) { key = ImGuiKey_LeftCtrl; }
1699 else if (key == ImGuiKey_RightSuper){ key = ImGuiKey_RightCtrl; }
1700 else if (key == ImGuiKey_LeftCtrl) { key = ImGuiKey_LeftSuper; }
1701 else if (key == ImGuiKey_RightCtrl) { key = ImGuiKey_RightSuper; }
1702 }
1703
1704 // Filter duplicate (in particular: key mods and gamepad analog values are commonly spammed)
1705 const ImGuiInputEvent* latest_event = FindLatestInputEvent(&g, ImGuiInputEventType_Key, (int)key);
1706 const ImGuiKeyData* key_data = ImGui::GetKeyData(&g, key);
1707 const bool latest_key_down = latest_event ? latest_event->Key.Down : key_data->Down;
1708 const float latest_key_analog = latest_event ? latest_event->Key.AnalogValue : key_data->AnalogValue;
1709 if (latest_key_down == down && latest_key_analog == analog_value)
1710 return;
1711
1712 // Add event
1713 ImGuiInputEvent e;
1714 e.Type = ImGuiInputEventType_Key;
1715 e.Source = ImGui::IsGamepadKey(key) ? ImGuiInputSource_Gamepad : ImGuiInputSource_Keyboard;
1716 e.EventId = g.InputEventsNextEventId++;
1717 e.Key.Key = key;
1718 e.Key.Down = down;
1719 e.Key.AnalogValue = analog_value;
1720 g.InputEventsQueue.push_back(e);
1721}
1722
1723void ImGuiIO::AddKeyEvent(ImGuiKey key, bool down)
1724{

Callers

nothing calls this directly

Calls 6

IsNamedKeyOrModFunction · 0.85
IsAliasKeyFunction · 0.85
FindLatestInputEventFunction · 0.85
GetKeyDataFunction · 0.85
IsGamepadKeyFunction · 0.85
push_backMethod · 0.45

Tested by

no test coverage detected