Skip to content

Conversation

@DarkDestry
Copy link

Issue

Current commented out implementation maps 2 keys to the same modifier key and call it separately.
Input state will flip flop between pressed and released when only 1 modifier key is pressed, resulting in UI slowdown due to repeated input event handling.

Fix

Use a single io.AddKeyEvent() call to activate modifier key when either modifier key is pressed.
Also passthrough the individual modifier keys itself so input handling can be done on the imgui layer for those specific keys.
Additionally map the OSX command key to super.

Resolves #78 and #75

Workaround

If you are here due to copy paste or any modifier key shortcut not working and the fix is not merged, place the following code into any Update() function.

void Update()
{
    var io = ImGui.GetIO();
    
    io.AddKeyEvent(ImGuiKey.LeftShift, Input.GetKey(KeyCode.LeftShift));
    io.AddKeyEvent(ImGuiKey.RightShift, Input.GetKey(KeyCode.RightShift));
    io.AddKeyEvent(ImGuiKey.ModShift, Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift));
    
    io.AddKeyEvent(ImGuiKey.LeftCtrl, Input.GetKey(KeyCode.LeftControl));
    io.AddKeyEvent(ImGuiKey.RightCtrl, Input.GetKey(KeyCode.RightControl));
    io.AddKeyEvent(ImGuiKey.ModCtrl, Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl));
    
    io.AddKeyEvent(ImGuiKey.LeftAlt, Input.GetKey(KeyCode.LeftAlt));
    io.AddKeyEvent(ImGuiKey.RightAlt, Input.GetKey(KeyCode.RightAlt));
    io.AddKeyEvent(ImGuiKey.ModAlt, Input.GetKey(KeyCode.LeftAlt) || Input.GetKey(KeyCode.RightAlt));
    
#if UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX || UNITY_IOS
    io.AddKeyEvent(ImGuiKey.LeftSuper, Input.GetKey(KeyCode.LeftCommand));
    io.AddKeyEvent(ImGuiKey.RightSuper, Input.GetKey(KeyCode.RightCommand));
    io.AddKeyEvent(ImGuiKey.ModSuper, Input.GetKey(KeyCode.LeftCommand) || Input.GetKey(KeyCode.RightCommand));
#else
    io.AddKeyEvent(ImGuiKey.LeftSuper, Input.GetKey(KeyCode.LeftWindows));
    io.AddKeyEvent(ImGuiKey.RightSuper, Input.GetKey(KeyCode.RightWindows));
    io.AddKeyEvent(ImGuiKey.ModSuper, Input.GetKey(KeyCode.LeftWindows) || Input.GetKey(KeyCode.RightWindows));
#endif
}

@donxemari
Copy link

donxemari commented May 1, 2025

The workaround did the trick, thanks much!
Do you think it might be somehow related to the mouse wheel scrolling being extremely slow now?
I got these two bugs in the last official update.

@DarkDestry
Copy link
Author

Do you think it might be somehow related to the mouse wheel scrolling being extremely slow now?

Mine scrolls fine so im not sure. Might want to create a reproducible sample and file it in issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Copy & Paste doesn't work

2 participants