MCPcopy Create free account
hub / github.com/Raais/ImStudio / AddKeyAnalogEvent

Method AddKeyAnalogEvent

src/third-party/imgui/imgui.cpp:1262–1302  ·  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

1260// - bool down: Is the key down? use false to signify a key release.
1261// - float analog_value: 0.0f..1.0f
1262void ImGuiIO::AddKeyAnalogEvent(ImGuiKey key, bool down, float analog_value)
1263{
1264 //if (e->Down) { IMGUI_DEBUG_LOG("AddKeyEvent() Key='%s' %d, NativeKeycode = %d, NativeScancode = %d\n", ImGui::GetKeyName(e->Key), e->Down, e->NativeKeycode, e->NativeScancode); }
1265 if (key == ImGuiKey_None)
1266 return;
1267 ImGuiContext& g = *GImGui;
1268 IM_ASSERT(&g.IO == this && "Can only add events to current context.");
1269 IM_ASSERT(ImGui::IsNamedKey(key)); // Backend needs to pass a valid ImGuiKey_ constant. 0..511 values are legacy native key codes which are not accepted by this API.
1270
1271 // Verify that backend isn't mixing up using new io.AddKeyEvent() api and old io.KeysDown[] + io.KeyMap[] data.
1272#ifndef IMGUI_DISABLE_OBSOLETE_KEYIO
1273 IM_ASSERT((BackendUsingLegacyKeyArrays == -1 || BackendUsingLegacyKeyArrays == 0) && "Backend needs to either only use io.AddKeyEvent(), either only fill legacy io.KeysDown[] + io.KeyMap[]. Not both!");
1274 if (BackendUsingLegacyKeyArrays == -1)
1275 for (int n = ImGuiKey_NamedKey_BEGIN; n < ImGuiKey_NamedKey_END; n++)
1276 IM_ASSERT(KeyMap[n] == -1 && "Backend needs to either only use io.AddKeyEvent(), either only fill legacy io.KeysDown[] + io.KeyMap[]. Not both!");
1277 BackendUsingLegacyKeyArrays = 0;
1278#endif
1279 if (ImGui::IsGamepadKey(key))
1280 BackendUsingLegacyNavInputArray = false;
1281
1282 // Partial filter of duplicates (not strictly needed, but makes data neater in particular for key mods and gamepad values which are most commonly spmamed)
1283 ImGuiKeyData* key_data = ImGui::GetKeyData(key);
1284 if (key_data->Down == down && key_data->AnalogValue == analog_value)
1285 {
1286 bool found = false;
1287 for (int n = g.InputEventsQueue.Size - 1; n >= 0 && !found; n--)
1288 if (g.InputEventsQueue[n].Type == ImGuiInputEventType_Key && g.InputEventsQueue[n].Key.Key == key)
1289 found = true;
1290 if (!found)
1291 return;
1292 }
1293
1294 // Add event
1295 ImGuiInputEvent e;
1296 e.Type = ImGuiInputEventType_Key;
1297 e.Source = ImGui::IsGamepadKey(key) ? ImGuiInputSource_Gamepad : ImGuiInputSource_Keyboard;
1298 e.Key.Key = key;
1299 e.Key.Down = down;
1300 e.Key.AnalogValue = analog_value;
1301 g.InputEventsQueue.push_back(e);
1302}
1303
1304void ImGuiIO::AddKeyEvent(ImGuiKey key, bool down)
1305{

Callers

nothing calls this directly

Calls 3

IsNamedKeyFunction · 0.85
IsGamepadKeyFunction · 0.85
push_backMethod · 0.80

Tested by

no test coverage detected