MCPcopy Create free account
hub / github.com/InteractiveComputerGraphics/SPlisHSPlasH / AddKeyAnalogEvent

Method AddKeyAnalogEvent

extern/imgui/imgui.cpp:1378–1416  ·  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

Source from the content-addressed store, hash-verified

1376// - bool down: Is the key down? use false to signify a key release.
1377// - float analog_value: 0.0f..1.0f
1378void ImGuiIO::AddKeyAnalogEvent(ImGuiKey key, bool down, float analog_value)
1379{
1380 //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); }
1381 if (key == ImGuiKey_None || !AppAcceptingEvents)
1382 return;
1383 ImGuiContext& g = *GImGui;
1384 IM_ASSERT(&g.IO == this && "Can only add events to current context.");
1385 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.
1386 IM_ASSERT(!ImGui::IsAliasKey(key)); // Backend cannot submit ImGuiKey_MouseXXX values they are automatically inferred from AddMouseXXX() events.
1387 IM_ASSERT(key != ImGuiMod_Shortcut); // We could easily support the translation here but it seems saner to not accept it (TestEngine perform a translation itself)
1388
1389 // Verify that backend isn't mixing up using new io.AddKeyEvent() api and old io.KeysDown[] + io.KeyMap[] data.
1390#ifndef IMGUI_DISABLE_OBSOLETE_KEYIO
1391 IM_ASSERT((BackendUsingLegacyKeyArrays == -1 || BackendUsingLegacyKeyArrays == 0) && "Backend needs to either only use io.AddKeyEvent(), either only fill legacy io.KeysDown[] + io.KeyMap[]. Not both!");
1392 if (BackendUsingLegacyKeyArrays == -1)
1393 for (int n = ImGuiKey_NamedKey_BEGIN; n < ImGuiKey_NamedKey_END; n++)
1394 IM_ASSERT(KeyMap[n] == -1 && "Backend needs to either only use io.AddKeyEvent(), either only fill legacy io.KeysDown[] + io.KeyMap[]. Not both!");
1395 BackendUsingLegacyKeyArrays = 0;
1396#endif
1397 if (ImGui::IsGamepadKey(key))
1398 BackendUsingLegacyNavInputArray = false;
1399
1400 // Filter duplicate (in particular: key mods and gamepad analog values are commonly spammed)
1401 const ImGuiInputEvent* latest_event = FindLatestInputEvent(ImGuiInputEventType_Key, (int)key);
1402 const ImGuiKeyData* key_data = ImGui::GetKeyData(key);
1403 const bool latest_key_down = latest_event ? latest_event->Key.Down : key_data->Down;
1404 const float latest_key_analog = latest_event ? latest_event->Key.AnalogValue : key_data->AnalogValue;
1405 if (latest_key_down == down && latest_key_analog == analog_value)
1406 return;
1407
1408 // Add event
1409 ImGuiInputEvent e;
1410 e.Type = ImGuiInputEventType_Key;
1411 e.Source = ImGui::IsGamepadKey(key) ? ImGuiInputSource_Gamepad : ImGuiInputSource_Keyboard;
1412 e.Key.Key = key;
1413 e.Key.Down = down;
1414 e.Key.AnalogValue = analog_value;
1415 g.InputEventsQueue.push_back(e);
1416}
1417
1418void ImGuiIO::AddKeyEvent(ImGuiKey key, bool down)
1419{

Callers

nothing calls this directly

Calls 5

IsNamedKeyOrModKeyFunction · 0.85
IsAliasKeyFunction · 0.85
IsGamepadKeyFunction · 0.85
FindLatestInputEventFunction · 0.85
push_backMethod · 0.45

Tested by

no test coverage detected