From 54c6eaeb960a404235d87f6d471dce95c1c9879c Mon Sep 17 00:00:00 2001 From: rdb Date: Fri, 3 May 2019 19:21:18 +0200 Subject: [PATCH] pgui: allow keyboard keys to be added as PGButton click buttons These will respond as clicks not when the mouse cursor is hovering over them, but when they have keyboard focus. Fixes #600 --- panda/src/pgui/pgButton.cxx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/panda/src/pgui/pgButton.cxx b/panda/src/pgui/pgButton.cxx index d1eba186c0..09a91120d4 100644 --- a/panda/src/pgui/pgButton.cxx +++ b/panda/src/pgui/pgButton.cxx @@ -115,7 +115,11 @@ release(const MouseWatcherParameter ¶m, bool background) { if (has_click_button(param.get_button())) { _button_down = false; if (get_active()) { - if (param.is_outside()) { + // Note that a "click" may come from a keyboard button press. In that + // case, instead of checking that the mouse cursor is still over the + // button, we check whether the item has keyboard focus. + if (param.is_outside() && + (MouseButton::is_mouse_button(param.get_button()) || !get_focus())) { set_state(S_ready); } else { set_state(S_rollover);