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