Skip to content
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

IsKeyPressed or IO.KeysDown not working #6523

Closed
nockawa opened this issue Jun 16, 2023 · 8 comments
Closed

IsKeyPressed or IO.KeysDown not working #6523

nockawa opened this issue Jun 16, 2023 · 8 comments

Comments

@nockawa
Copy link

nockawa commented Jun 16, 2023

Version/Branch of Dear ImGui:

Version: 1.89.2
Branch: Don't know

Back-end/Renderer/Compiler/OS
Using ImGuiNet / .net 7 / Windows

I feel this was something that used to work, I don't know if it's a change in my code or the recent upgrade to 1.89.2, but ImGui.IsKeyPressed[551] doesn't work anymore to detect a F key down.

I've tried to look in the source code of Dear ImGui for hint, I've tried SetNextFrameWantCaptureKeyboard(true), also try to dump GetIO.KeysData[]. But I can't get a detection of a key down.

Editing text in an input text box is working,
The Debug Log is outputing : `Processed: Text: f"

Basically, all I want is detecting if there's a given key pressed/released when a given Window has the focus.
I'm sure I'm missing something, but what?

Thanks

@ocornut
Copy link
Owner

ocornut commented Jun 16, 2023

You can browse Inputs in Metrics>Inputs and check IO in DebugLog>IO.
It looks like your backend is submitting characters but not keys.

@nockawa
Copy link
Author

nockawa commented Jun 16, 2023

image
Key Pressed displays the same thing that key down (obviously not when I take the screen shot).

By backend you mean the Windows implementation of DearImGui? I didn't change a thing, I remember upgrading my ImGuiNet package at some point, it also upgraded DearImGui IIRC.

Do you have pointers for me to try and troubleshoot/dig this further?

Thanks

@ocornut ocornut added the inputs label Jun 16, 2023
@ocornut
Copy link
Owner

ocornut commented Jun 16, 2023

It looks like your backends is not submitting keys properly as you are seeing a 70 which is not a valid ImGuiKey value.
It is however the ASCII value for 'F'. Prior to 1.87 backends used <512 values without a standard.

You didn't specify how you are expecting to detect the F KEY being pressed.
The right API would be IsKeyPressed(ImGuiKey_F) but ImGuiKey_F didn't even exist prior to 1.87.
If you want to use 1.87 features you need to use a backend submitting keys.

The legacy API would be IsKeyPressed('F') but that is entirely backend dependent and was never portable and is considered obsolete now.

See #4921

@ocornut
Copy link
Owner

ocornut commented Jun 16, 2023

AFAIK ImGuiNet is a language binding for C#/.Net but not a backend itself, your problem seems to lie in your backend version.

@nockawa
Copy link
Author

nockawa commented Jun 16, 2023

Ok, I wasn't aware of the change and I think I'll find my answer in #4921
Yes ImGuiNet is most about binding things to be used in .net.

Dear ImGui 1.89.2 (18920)
--------------------------------
sizeof(size_t): 8, sizeof(ImDrawIdx): 2, sizeof(ImDrawVert): 20
define: __cplusplus=199711
define: IMGUI_DISABLE_OBSOLETE_FUNCTIONS
define: _WIN32
define: _WIN64
define: _MSC_VER=1934
define: _MSVC_LANG=201402
define: IMGUI_HAS_VIEWPORT
define: IMGUI_HAS_DOCK
--------------------------------
io.BackendPlatformName: NULL
io.BackendRendererName: NULL
io.ConfigFlags: 0x00000040
 DockingEnable
io.ConfigViewportsNoDecoration
io.ConfigInputTextCursorBlink
io.ConfigWindowsResizeFromEdges
io.ConfigWindowsMoveFromTitleBarOnly
io.ConfigMemoryCompactTimer = 60.0
io.BackendFlags: 0x0000000A
 HasMouseCursors
 RendererHasVtxOffset

Thanks for the help.

@ocornut
Copy link
Owner

ocornut commented Jun 16, 2023

Find where you have calls to io.AddInputCharacter() and you'll find what/where your backend is, and then you need to look at updating this to use 1.87 IO API.

(In the meantime you can use IsKeyPressed('F') but that will be obsoleted and is backend-dependant so your code won't work with another backend.)

@nockawa
Copy link
Author

nockawa commented Jun 16, 2023

Ok, I found the call in ImGui.Net, I follow up there about the issue.
I'm closing this one, thanks again !

@nockawa nockawa closed this as completed Jun 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants