浏览代码

don't eat key events at all
only eat char events when Imgui wants keyboard control.
This lets the calling applications get access to key events if they need them and they check the IO flags.

Jeff Myers 1 年之前
父节点
当前提交
3d8ece299d
共有 1 个文件被更改,包括 14 次插入11 次删除
  1. 14 11
      rlImGui.cpp

+ 14 - 11
rlImGui.cpp

@@ -728,14 +728,14 @@ bool ImGui_ImplRaylib_ProcessEvents(void)
 		io.AddKeyEvent(ImGuiMod_Super, superDown);
 	LastSuperPressed = superDown;
 
-	// get the pressed keys, they are in event order
-	int keyId = GetKeyPressed();
-	while (keyId != 0)
+	// get the pressed keys, just walk the keys so we don
+	for (int keyId = KEY_NULL; keyId < KeyboardKey::KEY_KP_EQUAL; keyId++)
 	{
+        if (!IsKeyPressed(keyId))
+            continue;
 		auto keyItr = RaylibKeyMap.find(KeyboardKey(keyId));
 		if (keyItr != RaylibKeyMap.end())
 			io.AddKeyEvent(keyItr->second, true);
-		keyId = GetKeyPressed();
 	}
 
 	// look for any keys that were down last frame and see if they were down and are released
@@ -745,13 +745,16 @@ bool ImGui_ImplRaylib_ProcessEvents(void)
 			io.AddKeyEvent(keyItr.second, false);
 	}
 
-	// add the text input in order
-	unsigned int pressed = GetCharPressed();
-	while (pressed != 0)
-	{
-		io.AddInputCharacter(pressed);
-		pressed = GetCharPressed();
-	}
+    if (io.WantCaptureKeyboard)
+    {
+        // add the text input in order
+        unsigned int pressed = GetCharPressed();
+        while (pressed != 0)
+        {
+            io.AddInputCharacter(pressed);
+            pressed = GetCharPressed();
+        }
+    }
 
     if (io.ConfigFlags & ImGuiConfigFlags_NavEnableGamepad && IsGamepadAvailable(0))
     {