-
-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
Proper Method For Input Testing #703
Comments
After you've called ImGui::Render(), you can test the value of On Fri, 17 Jun 2016 at 16:35 atom0s [email protected] wrote:
|
BTW, I recommend you read through all the comments in imgui.h and the On Fri, 17 Jun 2016 at 16:40 Matt Davies [email protected] wrote:
|
As said above, but after ::Update(). Most typically ImGui request usage of the mouse when the cursor is hovering a window, but it handle other cases (whether a widget is active) and track clicks ownership so clicking in "void" and dragging over a window leaves the inputs to you. |
So far it seems that WantCaptureKeyboard / WantCaptureMouse never return true in my instance. My setup is an injected hook into games where the use of ImGui is not standardly built into the application. Instead I am hooking the rendering device and forcing my own code into the game etc. For that, I am hooking IDirect3DDevice8 and IDirect3DDevice9 (depending on the game) and using:
I have a window message hook in place via SetWindowLongPtr to intercept the window messages for input and allow ImGui to attempt to use it but it does not seem to work. Checking if either keyboard/mouse wants to be captured returns false and input is never handled. If I don't check them and just let both ImGui an the app fight over the input it works but then both are processing the input. |
My previous UI implementation uses AnTweakBar which includes a function:
This lets me test if the UI is going to handle keys at the current moment if any are passed to it. Does ImGui offer something like this? |
After reviewing the code more I have input working now. Sorry for the over-asked question, felt like I was doing something wrong in the first place vs. a bug etc. Got things working great now. I do still want to know if there is a key test method or possibly a chance of one being added It is very helpful for input systems that rely on things other than the window messages (WM_KEYDOWN/WM_KEYUP/WM_CHAR) to ensure proper input handling. (For example, DirectInput.) |
It's up to the user to hand I/O and feed the relevant data into ImGuiIO. On Sat, 18 Jun 2016 at 02:04 atom0s [email protected] wrote:
|
I understand that, but having a way to test if a key is going to be processed by ImGui for the frame would be helpful for blocking on a per-key basis. In my situation, I do not have just window messages being handled for input that I have to block for. When I setup input for ImGui, I have to be able to tell if it is going to process certain keys from within DirectInput to know if I should tell DirectInput to stop passing keys forward to the game. The game is old and uses a mixture of both DirectInput and WM_ messages from the WNDPROC of the window. I can give ImGui all the input information from the WNDPROC and make it work fine for input, however the game uses DirectInput for character movement and some other things as well, which in turn causes me to have to be able to detect input blocking for ImGui in two separate locations. This causes problems with certain things such as pressing enter in a text input box that is not multiline, for example, the Console example in the ImGui test window. Pressing enter here causes enter to still get sent to the game because checking io.WantCaptureKeyboard is false for this key press. A work-around I had to do was forcefully check if there was a window that had focus at all in ImGui (which the built-in function for that does not work properly). This is why I was wondering if there was an input testing method or the chance of one being added to test if ImGui is in a state where it would handle a key. As I said above, AnTweakBar has this feature via 'TwKeyTest', see this for more info: |
This really shouldn't be the case. It is a issue that would have been noticed already if there was actually a bug. I suspect your code may not be doing things in the right order. Please provide pseudo-code or a repro for it. |
It's hard to give example code because this is a closed source project. I'll share what I can though. Comments are to explain what is going on. |
As a very dumb test I have tried this:
And I haven't seen the keypress printed when pressing Return on a single-line input field. So that is pretty much enough of a proof that the feature works (the flag is updated every time you call ImGui::NewFrame()). I'm not sure about your code linked above. There's a lot of code/comments and it is hard to infer all the context.
This is what the flag does. As per your work-around you could also call |
Adding debug code to my keyboard setting function (KeyboardProc), I show that:
The key down event gets captured by the text box in ImGui but the keyup event does not which gets forwarded to the game and causes the game to think enter was pressed. The same happens with escape, pressing escape in the text box to remove its focus captures the keydown but not the keyup as focus is lost already from the keydown event. This is causing "half-keys" to be forwarded to the game still. For example typing 'test' then hitting escape in the text box:
Edit -- Looking inside of imgui.cpp I saw that InputTextEx handles enter presses on Key Down instead of Key Up which is the problem for me. I changed:
To the following to fix the problem:
|
You are correct about the key up events. If you actually need to ignore the key up event you could maintain an array of bool KeyPressOwnedByImGui[] that you set on keydown based on the WantCaptureKeyboard flag and filter the following keyup based on it.
|
I corrected the issue using the edited example above. I'm guessing your email did not get the edited post I made that you quoted. |
It isn't correct/standard behaviour to validate text with KeyUp on Return. I will look into improving the documentation based on this discussion. |
Just recently got into using ImGui and so far love it. However, I do have a question about how input is handled. In the examples, input is just force given to ImGui and not handled in a real-world environment where input going to the actual application / game is still happening.
What would be the proper method of checking if ImGui is going to handle input? I want to be able to allow ImGui have first dibs at input, and if nothing happens in the ui, allow it to continue to the actual application as it should.
The text was updated successfully, but these errors were encountered: