From 8a29f957e99c957efd11d6c279e5f97639f05d9e Mon Sep 17 00:00:00 2001 From: xander Date: Sat, 3 Sep 2022 10:59:58 +0100 Subject: prevent keyboard controls if not hovered or focused --- .../java/dev/isxander/yacl/gui/controllers/ActionController.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'src/main/java/dev/isxander/yacl/gui/controllers/ActionController.java') diff --git a/src/main/java/dev/isxander/yacl/gui/controllers/ActionController.java b/src/main/java/dev/isxander/yacl/gui/controllers/ActionController.java index d198c96..e0d0230 100644 --- a/src/main/java/dev/isxander/yacl/gui/controllers/ActionController.java +++ b/src/main/java/dev/isxander/yacl/gui/controllers/ActionController.java @@ -88,13 +88,16 @@ public class ActionController implements Controller> { @Override public boolean keyPressed(int keyCode, int scanCode, int modifiers) { - if (keyCode != GLFW.GLFW_KEY_ENTER && keyCode != GLFW.GLFW_KEY_SPACE && keyCode != GLFW.GLFW_KEY_KP_ENTER) { + if (!focused && !hovered) { return false; } - executeAction(); + if (keyCode == GLFW.GLFW_KEY_ENTER || keyCode == GLFW.GLFW_KEY_SPACE || keyCode == GLFW.GLFW_KEY_KP_ENTER) { + executeAction(); + return true; + } - return true; + return false; } @Override -- cgit