MCPcopy Create free account
hub / github.com/ShenCiao/CialloResearch / AddKeyAnalogEvent

Method AddKeyAnalogEvent

imgui/imgui.cpp:1382–1420  ·  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

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

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