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

Raise imgui keyboard event on WM_KEYDOWN and handle WantCaptureKeyboard #10

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions ImGuiScene/ImGui_Impl/Input/ImGui_Input_Impl_Direct.cs
Original file line number Diff line number Diff line change
Expand Up @@ -353,8 +353,13 @@ private bool UpdateMouseCursor()
// Submit key event
var key = VirtualKeyToImGuiKey((int)vk);
var scancode = ((int)lParam & 0xff0000) >> 16;
AddKeyEvent(key, isKeyDown, vk, scancode);
if (key != ImGuiKey.None && io.WantTextInput) {
AddKeyEvent(key, isKeyDown, vk, scancode);
return IntPtr.Zero;
}

if (io.WantCaptureKeyboard)
{
return IntPtr.Zero;
}

Expand Down Expand Up @@ -383,6 +388,10 @@ private bool UpdateMouseCursor()
io.AddInputCharacter((uint)wParam);
return IntPtr.Zero;
}
if (io.WantCaptureKeyboard)
{
return IntPtr.Zero;
}
break;
// this never seemed to work reasonably, but I'll leave it for now
case User32.WindowMessage.WM_SETCURSOR:
Expand Down Expand Up @@ -463,9 +472,7 @@ private void ProcessKeyEventsWorkarounds()
// Skip raising modifier keys if the game is focused.
// This allows us to raise the keys when one is held and the window becomes unfocused,
// but if we do not skip them, they will only be held down every 4th frame or so.
if (User32.GetForegroundWindow() == this._hWnd &&
(IsGamepadKey((ImGuiKey) i) ||
IsModKey((ImGuiKey) i)))
if (User32.GetForegroundWindow() == this._hWnd)
continue;
io.AddKeyEvent((ImGuiKey) i, false);
}
Expand Down