MCPcopy Create free account
hub / github.com/KebsCS/KBotExt / AddKeyAnalogEvent

Method AddKeyAnalogEvent

KBotExt/imgui/imgui.cpp:1425–1464  ·  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 IMPORTANT: THIS FUNCTION AND OTHER "ADD" GRABS THE CONTEXT FROM OUR INSTANCE. WE NEED TO ENSURE THAT ALL FUNCTION CALLS ARE FULLFILLIN

Source from the content-addressed store, hash-verified

1423// IMPORTANT: THIS FUNCTION AND OTHER "ADD" GRABS THE CONTEXT FROM OUR INSTANCE.
1424// WE NEED TO ENSURE THAT ALL FUNCTION CALLS ARE FULLFILLING THIS, WHICH IS WHY GetKeyData() HAS AN EXPLICIT CONTEXT.
1425void ImGuiIO::AddKeyAnalogEvent(ImGuiKey key, bool down, float analog_value)
1426{
1427 //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); }
1428 IM_ASSERT(Ctx != NULL);
1429 if (key == ImGuiKey_None || !AppAcceptingEvents)
1430 return;
1431 ImGuiContext& g = *Ctx;
1432 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.
1433 IM_ASSERT(ImGui::IsAliasKey(key) == false); // Backend cannot submit ImGuiKey_MouseXXX values they are automatically inferred from AddMouseXXX() events.
1434 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)
1435
1436 // Verify that backend isn't mixing up using new io.AddKeyEvent() api and old io.KeysDown[] + io.KeyMap[] data.
1437#ifndef IMGUI_DISABLE_OBSOLETE_KEYIO
1438 IM_ASSERT((BackendUsingLegacyKeyArrays == -1 || BackendUsingLegacyKeyArrays == 0) && "Backend needs to either only use io.AddKeyEvent(), either only fill legacy io.KeysDown[] + io.KeyMap[]. Not both!");
1439 if (BackendUsingLegacyKeyArrays == -1)
1440 for (int n = ImGuiKey_NamedKey_BEGIN; n < ImGuiKey_NamedKey_END; n++)
1441 IM_ASSERT(KeyMap[n] == -1 && "Backend needs to either only use io.AddKeyEvent(), either only fill legacy io.KeysDown[] + io.KeyMap[]. Not both!");
1442 BackendUsingLegacyKeyArrays = 0;
1443#endif
1444 if (ImGui::IsGamepadKey(key))
1445 BackendUsingLegacyNavInputArray = false;
1446
1447 // Filter duplicate (in particular: key mods and gamepad analog values are commonly spammed)
1448 const ImGuiInputEvent* latest_event = FindLatestInputEvent(&g, ImGuiInputEventType_Key, (int)key);
1449 const ImGuiKeyData* key_data = ImGui::GetKeyData(&g, key);
1450 const bool latest_key_down = latest_event ? latest_event->Key.Down : key_data->Down;
1451 const float latest_key_analog = latest_event ? latest_event->Key.AnalogValue : key_data->AnalogValue;
1452 if (latest_key_down == down && latest_key_analog == analog_value)
1453 return;
1454
1455 // Add event
1456 ImGuiInputEvent e;
1457 e.Type = ImGuiInputEventType_Key;
1458 e.Source = ImGui::IsGamepadKey(key) ? ImGuiInputSource_Gamepad : ImGuiInputSource_Keyboard;
1459 e.EventId = g.InputEventsNextEventId++;
1460 e.Key.Key = key;
1461 e.Key.Down = down;
1462 e.Key.AnalogValue = analog_value;
1463 g.InputEventsQueue.push_back(e);
1464}
1465
1466void ImGuiIO::AddKeyEvent(ImGuiKey key, bool down)
1467{

Callers

nothing calls this directly

Calls 5

IsNamedKeyOrModKeyFunction · 0.85
IsAliasKeyFunction · 0.85
IsGamepadKeyFunction · 0.85
FindLatestInputEventFunction · 0.85
GetKeyDataFunction · 0.85

Tested by

no test coverage detected