MCPcopy Create free account
hub / github.com/cinder/Cinder / AddKeyAnalogEvent

Method AddKeyAnalogEvent

src/imgui/imgui.cpp:1728–1766  ·  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

1726// IMPORTANT: THIS FUNCTION AND OTHER "ADD" GRABS THE CONTEXT FROM OUR INSTANCE.
1727// WE NEED TO ENSURE THAT ALL FUNCTION CALLS ARE FULFILLING THIS, WHICH IS WHY GetKeyData() HAS AN EXPLICIT CONTEXT.
1728void ImGuiIO::AddKeyAnalogEvent(ImGuiKey key, bool down, float analog_value)
1729{
1730 //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); }
1731 IM_ASSERT(Ctx != NULL);
1732 if (key == ImGuiKey_None || !AppAcceptingEvents)
1733 return;
1734 ImGuiContext& g = *Ctx;
1735 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.
1736 IM_ASSERT(ImGui::IsAliasKey(key) == false); // Backend cannot submit ImGuiKey_MouseXXX values they are automatically inferred from AddMouseXXX() events.
1737
1738 // MacOS: swap Cmd(Super) and Ctrl
1739 if (g.IO.ConfigMacOSXBehaviors)
1740 {
1741 if (key == ImGuiMod_Super) { key = ImGuiMod_Ctrl; }
1742 else if (key == ImGuiMod_Ctrl) { key = ImGuiMod_Super; }
1743 else if (key == ImGuiKey_LeftSuper) { key = ImGuiKey_LeftCtrl; }
1744 else if (key == ImGuiKey_RightSuper){ key = ImGuiKey_RightCtrl; }
1745 else if (key == ImGuiKey_LeftCtrl) { key = ImGuiKey_LeftSuper; }
1746 else if (key == ImGuiKey_RightCtrl) { key = ImGuiKey_RightSuper; }
1747 }
1748
1749 // Filter duplicate (in particular: key mods and gamepad analog values are commonly spammed)
1750 const ImGuiInputEvent* latest_event = FindLatestInputEvent(&g, ImGuiInputEventType_Key, (int)key);
1751 const ImGuiKeyData* key_data = ImGui::GetKeyData(&g, key);
1752 const bool latest_key_down = latest_event ? latest_event->Key.Down : key_data->Down;
1753 const float latest_key_analog = latest_event ? latest_event->Key.AnalogValue : key_data->AnalogValue;
1754 if (latest_key_down == down && latest_key_analog == analog_value)
1755 return;
1756
1757 // Add event
1758 ImGuiInputEvent e;
1759 e.Type = ImGuiInputEventType_Key;
1760 e.Source = ImGui::IsGamepadKey(key) ? ImGuiInputSource_Gamepad : ImGuiInputSource_Keyboard;
1761 e.EventId = g.InputEventsNextEventId++;
1762 e.Key.Key = key;
1763 e.Key.Down = down;
1764 e.Key.AnalogValue = analog_value;
1765 g.InputEventsQueue.push_back(e);
1766}
1767
1768void ImGuiIO::AddKeyEvent(ImGuiKey key, bool down)
1769{

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