-
-
Notifications
You must be signed in to change notification settings - Fork 9.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New IO keyboard/mouse/gamepad event API (1.87) recap #4921
Comments
Yes, this is a bug. It should be |
[OT] Not sure if somebody's interested... but when I saw the new "keyboard rectangle" in imgui_demo.cpp, I've soon tried to "extend" it. Here is what I've done so far [gist link]. |
I love it. I'm also so picky creature that I differentiate between ANSI and ISO layouts. :) |
IMPORTANT: If you have updated backends between January 10 and January 27 All backends have been updated. This only applies to you if you updated standard or custom backend between January 10 and January 27. If you use standard backends, simply update. If you use a custom backend change code above. |
...as far as I can see, in the glfw backend, when we "translate untranslated" keys, numbers in the keypad (= numpad) are converted to (or detected as) normal numbers of the main keyboard block (...well at least in my custom glfw backend). |
Not expected behavior; will fix soon! Thank you! |
What's the recommended way to remap keys in the new API? From what I can tell, it looks like doing so after this change requires customizing the backend, whereas previously that could be done simply by modifying io.KeyMap to point to a different io.KeysDown? |
@PeterJohnson What/why were you remapping before? Everything in |
For my use case, there is another application running on the system that has a global (system-wide) listener on the spacebar and Enter keys. While it's relatively easy to avoid the use of spacebar for numeric entry, the use of Enter for committing changes to InputText-based controls is hardcoded, so the easiest workaround was to provide users a way to remap another key (e.g. right ctrl) to the Enter key. Is not acceptable for my use case to commit the value for every keypress. I agree this is a relatively unusual use case and modifying the backend (GLFW in my case) to support key remap is probably the right answer. |
Ah yeah, the driver station? 😅 That makes sense. I haven't tested it super thoroughly, but this might be good enough for your use-case: //...
ImGui::NewFrame();
if (ImGui::IsKeyPressed(ImGuiKey_RightCtrl))
{
io.AddKeyEvent(ImGuiKey_Enter, true);
io.AddKeyEvent(ImGuiKey_Enter, false);
}
//... Note that this will break using right control for shortcuts. (IE: Right Control + V to paste.) If you want to truly remap it you could install your own Another alternative would be to manipulate (Or like you said you could just modify the GLFW backend, but then you have to deal with merging changes all the time.) (If you want me to elaborate on one of these alternatives it would be better to open a separate issue.) |
@ocornut its really cool update but what about key/mouse intercompatibility #4858 (comment) ? |
We discovered a backward-compatibility regression in 1.87
Reads via We'll see if we can come up with a fix. But changing your app to use IsKeyDown() will fix things. |
Fixed by commit 5659db5. |
Codechanges: * GUIUtils, InputEngine: `getModifierKeyName()` replaced OIS keycodes with OgreBites/SDL keycodes * ImGuiAngelscript: commented out some dead items, added (ImGuiKey) casts where needed, see ocornut/imgui#4921 * GUI_VehicleButtons: build fix for `ImGui::ImageButton()` - added parameter ID-string. * GUI_RepositorySelector: updated thumbnail downloading to use new OGRE WorkQueue API, see https://github.com/OGRECave/ogre/blob/master/Docs/14-Notes.md#task-based-workqueue * Application.h, main.cpp: added ✉️ `MSG_NET_DOWNLOAD_REPOTHUMB_SUCCESS`, used instead of OGRE WorkQueue's `addMainThreadTask` for consistency across the various background threads in the codebase. * GodRaysManager: build fix - RENDER_QUEUE_9 was removed from OGRE, using 8. * RttManager: rendersystem-specific `getProjectionMatrixRS()` was removed from OGRE, using portable `getProjectionMatrix()`
Status: builds and runs, but crashes when loading terrain (RenderingAPIException) Codechanges: * ImGuiAngelscript: commented out some dead items, added (ImGuiKey) casts where needed, see ocornut/imgui#4921 * GUI_RepositorySelector: updated thumbnail downloading to use new OGRE WorkQueue API, see https://github.com/OGRECave/ogre/blob/master/Docs/14-Notes.md#task-based-workqueue * Application.h, main.cpp: added ✉️ `MSG_NET_DOWNLOAD_REPOTHUMB_SUCCESS`, used instead of OGRE WorkQueue's `addMainThreadTask` for consistency across the various background threads in the codebase. * GodRaysManager, skyx/VClouds: build fix - RENDER_QUEUE_9 was removed from OGRE, using 8. * RttManager: rendersystem-specific `getProjectionMatrixRS()` was removed from OGRE, using portable `getProjectionMatrix()` * TerrainGeometryManager: updated (simplified!) to match OGRE14 API. * FlexBody: `reorganiseBuffers()`: updated for OGRE14 - there's no 'optimalUsage' param anymore. * RTTLayer, DashBoardManager: build fix for MyGUI API change.
Since d0da79c, |
There doesn't seem to be an (Does this matter? Maybe it mostly doesn't, but if you want to use this stuff for keyboard shortcuts then it feels like you'll need an index for every potential pressable physical key. I guess anything that wants text input can get it via the text input mechanism, and aside from that you mostly don't need to worry about specific keys.) Thanks, --Tom |
@tom-seddon I think that key might indeed be missing, it's not a dedicated key on the US English keyboard layout (and some others I checked) so it was probably overlooked. Does the inputs debugger react when you press the key? That'd be the way to confirm for sure. (From the demo go to Tools > Metrics/Debugger and expand the Inputs section.) |
I've raised an issue, that refers more vaguely to the extra key on the ISO-type keyboard layout. As that's the basic issue here I think: ISO-type keyboards have an extra key that ANSI-type keyboards don't, and there's no value in the enum to cover this. Thanks, --Tom |
Keys are not Characters. They are meant to mostly associate to physical keys. The complication comes from the fact that high-level systems such as GLFW and SDL and some Win32 layers don't expose characters when certain modifiers are pressed (e.g. CTRL) so it's complicated to use them for shortcut. |
Status: builds and runs, but crashes when loading terrain (RenderingAPIException) Codechanges: * ImGuiAngelscript: commented out some dead items, added (ImGuiKey) casts where needed, see ocornut/imgui#4921 * GUI_RepositorySelector: updated thumbnail downloading to use new OGRE WorkQueue API, see https://github.com/OGRECave/ogre/blob/master/Docs/14-Notes.md#task-based-workqueue * Application.h, main.cpp: added ✉️ `MSG_NET_DOWNLOAD_REPOTHUMB_SUCCESS`, used instead of OGRE WorkQueue's `addMainThreadTask` for consistency across the various background threads in the codebase. * GodRaysManager, skyx/VClouds: build fix - RENDER_QUEUE_9 was removed from OGRE, using 8. * RttManager: rendersystem-specific `getProjectionMatrixRS()` was removed from OGRE, using portable `getProjectionMatrix()` * TerrainGeometryManager: updated (simplified!) to match OGRE14 API. * FlexBody: `reorganiseBuffers()`: updated for OGRE14 - there's no 'optimalUsage' param anymore. * RTTLayer, DashBoardManager: build fix for MyGUI API change.
…ISABLE_OBSOLETE_FUNCTIONS is set. (#4921)
Hi there, although I'm loving the unification of inputs, I was wondering if there is a way to "capture" gamepad input only from a dear imgui window ?
|
Please open a new issue. |
EDIT 2022/11/15: Dear ImGui 1.89 made
ImGuiKey
a strongly-typed enum, which broke backward compatibility with using legacy backend-specific indices (e.g.IsKeyPressed(GLFW_KEY_A)
needs castingIsKeyPressing((ImGuiKey)GLFW_KEY_A)
. I am not entirely sure this was the right decision as this is unusually breaking, but fix is trivial and should encourage moving to new API so leaving the strongly-typed enum for now.EDIT 2022/02/29: We discovered a backward-compatibility regression in 18700:
io.KeysDown[]
won't work with new backends.io.KeysDown[GetKeyIndex[XXX])
will buffer overflow in old and new backends.Reads via
IsKeyDown()
function are always working, this only affect direct array access This was fixed in 18708 (commit 5659db5)(This is a followup on #4858 now that things have settled)
We (@thedmd @ocornut) have completely revamped IO API in 1.87 (the way backend communicate with dear imgui to submit inputs)
All backends have been updated to use new API.
Both user code and old backends should be backward compatible (apart from a few rare edge cases) but we encourage you to transition.
Additions:
io.AddKeyEvent()
,io.AddKeyAnalogEvent()
,removed jan 27,io.AddKeyModsEvent()
io.AddMousePosEvent()
,io.AddMouseButtonEvent()
,io.AddMouseWheelEvent()
,io.SetKeyEventNativeData()
(for legacy support).ImGuiKey
now contains a full keyset (e.g.ImGuiKey_F1
) this allow using full range of keyboard inputs in a portable manner, which was previously impossible as we encouraged use of native indices. This will make it easier for people to share code/extensions publicly or across multiple codebases.ImGuiKey
also contains gamepad axises/buttonsImGuiKey_GamepadDpadUp
) unifying input sources.io.ConfigInputTrickleEventQueue == false
) which massively improve input experience with low framerate.ImGuiKey_A
will be submitted when pressing the key which user would need to press to emit an "A" character, allowing for translated shortcuts.Those changes will constitute the bulk of 1.87.
If you want to help, please upgrade today :)
Transition Guide
If you are using a standard backend (RECOMMENDED) just update it to latest!
If you have are using a custom backend:
Keyboard:
io.KeyMap[]
,io.KeysDown[]
-> backend should callio.AddKeyEvent()
io.AddKeyEvent()
and you want legacy user code to still work with legacy indices, also callio.SetKeyEventNativeData()
.IsKeyPressed(MY_NATIVE_KEY_XXX)
-> callIsKeyPressed(ImGuiKey_XXX)
(OLD CODE WILL STILL WORK*)IsKeyPressed(GetKeyIndex(ImGuiKey_XXX))
-> callIsKeyPressed(ImGuiKey_XXX)
(OLD CODE WILL STILL WORK*)int user_key_index
now takeImGuiKey key
:IsKeyDown()
,IsKeyPressed()
,IsKeyReleased()
,GetKeyPressedAmount()
.GetKeyName()
helper function.GetKeyIndex()
: it is now unnecessary and will now return the same value.(* until
IMGUI_DISABLE_OBSOLETE_KEYIO
is set.In a few versions,)IMGUI_DISABLE_OBSOLETE_FUNCTIONS
will automatically set it(since 1.90, defining
IMGUI_DISABLE_OBSOLETE_FUNCTIONS
automatically definesIMGUI_DISABLE_OBSOLETE_KEYIO
.)(* and unless the backend forgot to call
io.SetKeyEventNativeData()
)Mouse:
io.MousePos
-> backend should callio.AddMousePosEvent()
io.MouseDown[]
-> backend should callio.AddMouseButtonEvent()
io.MouseWheel
,io.MouseWheelH
-> backend should callio.AddMouseWheelEvent()
io.MouseHoveredViewport
-> backend should callio.AddMouseViewportEvent()
Gamepad/Nav:
io.NavInputs[]
-> backend should callio.AddKeyEvent()
/io.AddKeyAnalogEvent()
withImGuiKey_GamepadXXX
values.What is input queue trickling?
TL;DR; if you submit "Key A went down, then went up, then went down, then went up" during the same Dear ImGui frame, previously events would be missed and it was the application/backend responsibility to submit those events wisely. We moved that responsibility to the core library now. Because most of Dear ImGui code and widgets are reading inputs levels (rather than events), we spread those events over multiple frames when necessary. This makes dear imgui easier to use at low framerate (e.g. 10 FPS).
Backends polling inputs vs handling events
One gotcha is that if you submit events it is preferable to submit then in the right order.
If you transition to new API make sure you are submitting events in the order they come from your OS / platform layer. Normally this should be the default. But because we are punks, our old backends had a tendency to be polling some input state instead of reacting to events, which effectively "lost" their order (e.g. which have changed first, Mouse Position or Mouse Button state?). We have now transitioned all standard backends to be reacting on events rather than polling. If you used your own backend maybe you already behaved better.
Demo
You can see pressed keys in the demo + drawing a small section of a keyboard for no other reason that it being fun.
Reference changes (e.g. to platform backends)
ALWAYS REFER TO FINAL VERSION AS SOME MINOR STUFF MAY HAVE BEEN RENAMED/CHANGED SINCE THE INTERMEDIARY COMMITS. Those references commits are here to help understanding what changed, if you need to update a custom backend.
Core lib
Win32 backend
GLFW backend
SDL backend
Other backends
List of keys
Questions?
(Will be updated over time)
Q: It is ok to call
io.AddXXXEvent()
functions every frame with unchanged data?A: Yes.
The text was updated successfully, but these errors were encountered: