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
| 1336 | // - bool down: Is the key down? use false to signify a key release. |
| 1337 | // - float analog_value: 0.0f..1.0f |
| 1338 | void ImGuiIO::AddKeyAnalogEvent(ImGuiKey key, bool down, float analog_value) |
| 1339 | { |
| 1340 | //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); } |
| 1341 | if (key == ImGuiKey_None || !AppAcceptingEvents) |
| 1342 | return; |
| 1343 | ImGuiContext& g = *GImGui; |
| 1344 | IM_ASSERT(&g.IO == this && "Can only add events to current context."); |
| 1345 | IM_ASSERT(ImGui::IsNamedKeyOrModKey(key)); // Backend needs to pass a valid ImGuiKey_ constant. 0..511 values are legacy native key codes which are not accepted by this API. |
| 1346 | IM_ASSERT(!ImGui::IsAliasKey(key)); // Backend cannot submit ImGuiKey_MouseXXX values they are automatically inferred from AddMouseXXX() events. |
| 1347 | |
| 1348 | // Verify that backend isn't mixing up using new io.AddKeyEvent() api and old io.KeysDown[] + io.KeyMap[] data. |
| 1349 | #ifndef IMGUI_DISABLE_OBSOLETE_KEYIO |
| 1350 | IM_ASSERT((BackendUsingLegacyKeyArrays == -1 || BackendUsingLegacyKeyArrays == 0) && "Backend needs to either only use io.AddKeyEvent(), either only fill legacy io.KeysDown[] + io.KeyMap[]. Not both!"); |
| 1351 | if (BackendUsingLegacyKeyArrays == -1) |
| 1352 | for (int n = ImGuiKey_NamedKey_BEGIN; n < ImGuiKey_NamedKey_END; n++) |
| 1353 | IM_ASSERT(KeyMap[n] == -1 && "Backend needs to either only use io.AddKeyEvent(), either only fill legacy io.KeysDown[] + io.KeyMap[]. Not both!"); |
| 1354 | BackendUsingLegacyKeyArrays = 0; |
| 1355 | #endif |
| 1356 | if (ImGui::IsGamepadKey(key)) |
| 1357 | BackendUsingLegacyNavInputArray = false; |
| 1358 | |
| 1359 | // Filter duplicate (in particular: key mods and gamepad analog values are commonly spammed) |
| 1360 | const ImGuiInputEvent* latest_event = FindLatestInputEvent(ImGuiInputEventType_Key, (int)key); |
| 1361 | const ImGuiKeyData* key_data = ImGui::GetKeyData(key); |
| 1362 | const bool latest_key_down = latest_event ? latest_event->Key.Down : key_data->Down; |
| 1363 | const float latest_key_analog = latest_event ? latest_event->Key.AnalogValue : key_data->AnalogValue; |
| 1364 | if (latest_key_down == down && latest_key_analog == analog_value) |
| 1365 | return; |
| 1366 | |
| 1367 | // Add event |
| 1368 | ImGuiInputEvent e; |
| 1369 | e.Type = ImGuiInputEventType_Key; |
| 1370 | e.Source = ImGui::IsGamepadKey(key) ? ImGuiInputSource_Gamepad : ImGuiInputSource_Keyboard; |
| 1371 | e.Key.Key = key; |
| 1372 | e.Key.Down = down; |
| 1373 | e.Key.AnalogValue = analog_value; |
| 1374 | g.InputEventsQueue.push_back(e); |
| 1375 | } |
| 1376 | |
| 1377 | void ImGuiIO::AddKeyEvent(ImGuiKey key, bool down) |
| 1378 | { |
nothing calls this directly
no test coverage detected