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
| 1837 | // IMPORTANT: THIS FUNCTION AND OTHER "ADD" GRABS THE CONTEXT FROM OUR INSTANCE. |
| 1838 | // WE NEED TO ENSURE THAT ALL FUNCTION CALLS ARE FULFILLING THIS, WHICH IS WHY GetKeyData() HAS AN EXPLICIT CONTEXT. |
| 1839 | void ImGuiIO::AddKeyAnalogEvent(ImGuiKey key, bool down, float analog_value) |
| 1840 | { |
| 1841 | //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); } |
| 1842 | IM_ASSERT(Ctx != NULL); |
| 1843 | if (key == ImGuiKey_None || !AppAcceptingEvents) |
| 1844 | return; |
| 1845 | ImGuiContext& g = *Ctx; |
| 1846 | 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. |
| 1847 | IM_ASSERT(ImGui::IsAliasKey(key) == false); // Backend cannot submit ImGuiKey_MouseXXX values they are automatically inferred from AddMouseXXX() events. |
| 1848 | |
| 1849 | // MacOS: swap Cmd(Super) and Ctrl |
| 1850 | if (g.IO.ConfigMacOSXBehaviors) |
| 1851 | { |
| 1852 | if (key == ImGuiMod_Super) { key = ImGuiMod_Ctrl; } |
| 1853 | else if (key == ImGuiMod_Ctrl) { key = ImGuiMod_Super; } |
| 1854 | else if (key == ImGuiKey_LeftSuper) { key = ImGuiKey_LeftCtrl; } |
| 1855 | else if (key == ImGuiKey_RightSuper){ key = ImGuiKey_RightCtrl; } |
| 1856 | else if (key == ImGuiKey_LeftCtrl) { key = ImGuiKey_LeftSuper; } |
| 1857 | else if (key == ImGuiKey_RightCtrl) { key = ImGuiKey_RightSuper; } |
| 1858 | } |
| 1859 | |
| 1860 | // Filter duplicate (in particular: key mods and gamepad analog values are commonly spammed) |
| 1861 | const ImGuiInputEvent* latest_event = FindLatestInputEvent(&g, ImGuiInputEventType_Key, (int)key); |
| 1862 | const ImGuiKeyData* key_data = ImGui::GetKeyData(&g, key); |
| 1863 | const bool latest_key_down = latest_event ? latest_event->Key.Down : key_data->Down; |
| 1864 | const float latest_key_analog = latest_event ? latest_event->Key.AnalogValue : key_data->AnalogValue; |
| 1865 | if (latest_key_down == down && latest_key_analog == analog_value) |
| 1866 | return; |
| 1867 | |
| 1868 | // Add event |
| 1869 | ImGuiInputEvent e; |
| 1870 | e.Type = ImGuiInputEventType_Key; |
| 1871 | e.Source = ImGui::IsGamepadKey(key) ? ImGuiInputSource_Gamepad : ImGuiInputSource_Keyboard; |
| 1872 | e.EventId = g.InputEventsNextEventId++; |
| 1873 | e.Key.Key = key; |
| 1874 | e.Key.Down = down; |
| 1875 | e.Key.AnalogValue = analog_value; |
| 1876 | g.InputEventsQueue.push_back(e); |
| 1877 | } |
| 1878 | |
| 1879 | void ImGuiIO::AddKeyEvent(ImGuiKey key, bool down) |
| 1880 | { |
nothing calls this directly
no test coverage detected