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

Fixed bug : ImGui.IsKeyPressed API didn't work on XNA project. #1

Open
wants to merge 2 commits into
base: imgui-internal
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
20 changes: 18 additions & 2 deletions src/ImGui.NET.SampleProgram.XNA/ImGuiRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,25 @@ protected virtual void UpdateInput()
var mouse = Mouse.GetState();
var keyboard = Keyboard.GetState();

for (int i = 0; i < _keys.Count; i++)
// This implementation is WRONG, because it only handled ImGuiKey-related native key, and it didn't handle other native keys.
//for (int i = 0; i < _keys.Count; i++)
//{
// io.KeysDown[_keys[i]] = keyboard.IsKeyDown((Keys)_keys[i]);
//}

// Here is my implementation, which works fine when you call ImGui.IsKeyPressed(uint user_key_index) API.

// Set all of the XNA native keys' state to NotKeyDown.
for (var key = Keys.None; key <= Keys.OemEnlW; key++)
{
io.KeysDown[(int)key] = false;
}

// Set io.KeysDown[nativeKeyIndex] from XNA keyboard state.
var pressedKeys = keyboard.GetPressedKeys();
foreach (var pressedKey in pressedKeys)
{
io.KeysDown[_keys[i]] = keyboard.IsKeyDown((Keys)_keys[i]);
io.KeysDown[(int)pressedKey] = true;
}

io.KeyShift = keyboard.IsKeyDown(Keys.LeftShift) || keyboard.IsKeyDown(Keys.RightShift);
Expand Down