Bläddra i källkod

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 år sedan
förälder
incheckning
3d8ece299d
1 ändrade filer med 14 tillägg och 11 borttagningar
  1. 14 11
      rlImGui.cpp

+ 14 - 11
rlImGui.cpp

@@ -728,14 +728,14 @@ bool ImGui_ImplRaylib_ProcessEvents(void)
 		io.AddKeyEvent(ImGuiMod_Super, superDown);
 		io.AddKeyEvent(ImGuiMod_Super, superDown);
 	LastSuperPressed = 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));
 		auto keyItr = RaylibKeyMap.find(KeyboardKey(keyId));
 		if (keyItr != RaylibKeyMap.end())
 		if (keyItr != RaylibKeyMap.end())
 			io.AddKeyEvent(keyItr->second, true);
 			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
 	// 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);
 			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))
     if (io.ConfigFlags & ImGuiConfigFlags_NavEnableGamepad && IsGamepadAvailable(0))
     {
     {