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.
| 1287 | // - ImGuiKey key: Translated key (as in, generally ImGuiKey_A matches the key end-user would use to emit an 'A' character) |
| 1288 | // - bool down: Is the key down? use false to signify a key release. |
| 1289 | void ImGuiIO::AddKeyEvent(ImGuiKey key, bool down) |
| 1290 | { |
| 1291 | //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); } |
| 1292 | if (key == ImGuiKey_None) |
| 1293 | return; |
| 1294 | ImGuiContext& g = *GImGui; |
| 1295 | IM_ASSERT(&g.IO == this && "Can only add events to current context."); |
| 1296 | 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. |
| 1297 | |
| 1298 | // Verify that backend isn't mixing up using new io.AddKeyEvent() api and old io.KeysDown[] + io.KeyMap[] data. |
| 1299 | #ifndef IMGUI_DISABLE_OBSOLETE_KEYIO |
| 1300 | IM_ASSERT((BackendUsingLegacyKeyArrays == -1 || BackendUsingLegacyKeyArrays == 0) && "Backend needs to either only use io.AddKeyEvent(), either only fill legacy io.KeysDown[] + io.KeyMap[]. Not both!"); |
| 1301 | if (BackendUsingLegacyKeyArrays == -1) |
| 1302 | for (int n = ImGuiKey_NamedKey_BEGIN; n < ImGuiKey_NamedKey_END; n++) |
| 1303 | IM_ASSERT(KeyMap[n] == -1 && "Backend needs to either only use io.AddKeyEvent(), either only fill legacy io.KeysDown[] + io.KeyMap[]. Not both!"); |
| 1304 | BackendUsingLegacyKeyArrays = 0; |
| 1305 | #endif |
| 1306 | |
| 1307 | ImGuiInputEvent e; |
| 1308 | e.Type = ImGuiInputEventType_Key; |
| 1309 | e.Source = ImGuiInputSource_Keyboard; |
| 1310 | e.Key.Key = key; |
| 1311 | e.Key.Down = down; |
| 1312 | g.InputEventsQueue.push_back(e); |
| 1313 | } |
| 1314 | |
| 1315 | // [Optional] Call after AddKeyEvent(). |
| 1316 | // Specify native keycode, scancode + Specify index for legacy <1.87 IsKeyXXX() functions with native indices. |
no test coverage detected