Clicking a PushButton using the enter key

If you found a bug in our library or on our website, please report it in this section. In this forum you can also make concrete suggestions or feature requests.

Moderators: CEGUI MVP, CEGUI Team

BigG
Not too shy to talk
Not too shy to talk
Posts: 22
Joined: Tue Oct 13, 2009 14:25

Clicking a PushButton using the enter key

Postby BigG » Thu Nov 25, 2010 13:45

Hi,

I came across the following problem: I want to fire the onClicked() event of a CEGUI::PushButton when the button has the input focus and the enter/return key is pressed.
Surprisingly, I was unable to find any topic related to this in here, so I came up a few solutions:

1) The one requiring fewer changes to the library, but requiring more user-code: adding a public procedure click() to CEGUI::PushButton:
in CEGUIPushButton.h

Code: Select all

virtual void click(void);

in CEGUIPushButton.cpp

Code: Select all

void PushButton::click(void)
{
    WindowEventArgs args(this);
    onClicked(args);
}

Using this procedure I could add some OnKeyDown/OnKeyUp handler to every button in my interface that I want to be enter-clickable.

2) The one requiring the more changes to the library, but almost no user code: adding a boolean property "EnterClickable" to CEGUI::PushButton:
I didn't write the required code for that yet, but it should be a pretty trivial task, which I could fulfill if required :)
The idea is simple: adding a boolean property "EnterClickable" to the PushButton class. Also, it would require an additional event handler in the PushButton class that handles keyboard input, checks if the clicked key is the enter key and if "EnterClickable" is true, and if so, fires the onClicked event.


Maybe a combination of both would be handy in other cases as well - like adding a click() procedure usable by the user but also the "EnterClickable" property so that the most common use of the click() procedure would be handled build-in and also configurable in the layout files and such.

I'll be happy about any feedback on this ;)

Greetings, BigG

Jamarr
CEGUI MVP
CEGUI MVP
Posts: 812
Joined: Tue Jun 03, 2008 23:59
Location: USA

Re: Clicking a PushButton using the enter key

Postby Jamarr » Mon Nov 29, 2010 22:19

I am sure you can achieve this without modifying any CEGUI source code by sub-classing CEGUI::PushButton, subscribing to KeyDown/KeyUp, and firing the clicked event as necessary.
If somebody helps you by replying to your thread, upvote him/her as a thanks! Make sure to include your CEGUI.log and everything you tried when posting! And remember that we are not magicians!


Return to “Bug Reports, Suggestions, Feature Requests”

Who is online

Users browsing this forum: No registered users and 1 guest