From 035cc92ee2a435ff1d663e2037f543578dd2578a Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Sat, 14 Apr 2012 01:07:23 +0300 Subject: Block enter key from pressing active button. --- src/gui/widgets/button.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'src/gui/widgets/button.cpp') diff --git a/src/gui/widgets/button.cpp b/src/gui/widgets/button.cpp index c99f46149..9519c144f 100644 --- a/src/gui/widgets/button.cpp +++ b/src/gui/widgets/button.cpp @@ -448,3 +448,26 @@ void Button::setCaption(const std::string& caption) mCaption = caption; // adjustSize(); } + +void Button::keyPressed(gcn::KeyEvent& keyEvent) +{ + gcn::Key key = keyEvent.getKey(); + + if (key.getValue() == gcn::Key::SPACE) + { + mKeyPressed = true; + keyEvent.consume(); + } +} + +void Button::keyReleased(gcn::KeyEvent& keyEvent) +{ + gcn::Key key = keyEvent.getKey(); + + if (key.getValue() == gcn::Key::SPACE && mKeyPressed) + { + mKeyPressed = false; + distributeActionEvent(); + keyEvent.consume(); + } +} -- cgit v1.2.3-70-g09d2