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

Copy & paste using hotkeys produces an extra 'c' or 'v', so as cut, select all. #279

Closed
YukinoHayakawa opened this issue Jul 20, 2015 · 9 comments
Labels

Comments

@YukinoHayakawa
Copy link

I'm using the latest imgui repository with glfw as fore-end (from opengl_example) under ubuntu 15.04. While I've found that manipulating an InputText with hotkeys will cause some extra characters to appear. For examples:

  • Type 123456, press Ctrl+X, the InputText is cleared while 123456x is apparent in cliboard.
  • Assuming string foobar is in clipboard, press Ctrl+V when focused on a InputText, vfoobar will be shown in it.
  • Using Ctrl+C producing analogous problems.
  • Press Ctrl+A twice will replace original content with a.

One possible solution I've found it to ignore any inputted character when modifier keys are pressed in ImGui_ImplGlfw_CharCallback.

@YukinoHayakawa YukinoHayakawa changed the title Copy & paste using hotkeys produces an extra 'c' or 'v', so as cut. Copy & paste using hotkeys produces an extra 'c' or 'v', so as cut, select all. Jul 20, 2015
@ocornut
Copy link
Owner

ocornut commented Jul 20, 2015

I suppose it means that GLFW isn't behaving consistently on all OS. On Windows I don't get a character callback when modifiers are pressed. We should be able to add this test in the callback function if we can get the right modifiers at this point in time. Reading io.KeyCtrl etc. is probably good enough but in theory they may data from the previous frame.

I have another problem then. Eventually we would need to receive those characters callback and I will need to use them for other features such as pressing ALT+letter to open a menu with the keyboard.

@ocornut
Copy link
Owner

ocornut commented Jul 20, 2015

OK I have just noticed that GLFW has a function glfwSetCharModsCallback() that does just that. So we'll need to use this and make the filtering in imgui code.

@ocornut
Copy link
Owner

ocornut commented Aug 20, 2015

Should be fixed but I couldn't test it on your platform. @AkizukiRyoko can you confirm it is fixed?

@ocornut
Copy link
Owner

ocornut commented Aug 20, 2015

That function was introduced in glfw 3.1 which apparently isn't widespread..

@ocornut ocornut reopened this Aug 20, 2015
@ocornut
Copy link
Owner

ocornut commented Aug 20, 2015

@AkizukiRyoko Which version of GLFW are/were you using?

ocornut added a commit that referenced this issue Aug 20, 2015
@ocornut
Copy link
Owner

ocornut commented Aug 20, 2015

I have fixed a workaround but please let me know which version of GLFW you had the issue with.!

@YukinoHayakawa
Copy link
Author

It appears that the problem has gone on my platform (glfw 3.0.4). Thank you.

@borg
Copy link

borg commented Jan 12, 2017

Using this openFrameworks implementation on OSX still getting c and v instead of copy paste. Not sure it's a mismatch between GLFW implementation of cmd (GLFW_KEY_LEFT_SUPER) and oF or ImGui, but extending the previous fix to include check for is_super_down seems to solve it.

glfwGetVersionString 3.1.0 Cocoa NSGL chdir menubar retina
imgui.cpp 7730

            if (!(is_ctrl_down && !is_alt_down) && !is_super_down && is_editable)
            {
                for (int n = 0; n < IM_ARRAYSIZE(g.IO.InputCharacters) && g.IO.InputCharacters[n]; n++)
                    if (unsigned int c = (unsigned int)g.IO.InputCharacters[n])
                    {
                        // Insert character if they pass filtering
                        if (!InputTextFilterCharacter(&c, flags, callback, user_data))
                            continue;
                        edit_state.OnKeyPressed((int)c);
                    }
            }

@ocornut
Copy link
Owner

ocornut commented Jan 15, 2017

I believe this should be fixed at the level of either GLFW or ofxImGui, you can perfectly filter the characters using the same condition.

Not knowing if certain IME can emit characters using the Super key isn't safe to filter it for everyone, but if you filter it yourself it may be ok.

@ocornut ocornut added inputs and removed in progress labels Apr 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants