[FXRuby] - Catching keypresses

Hi,

I want my FXRuby application to close when the user hits any key (the
application does not require any other interaction at all).

I tried to connect the FXMainWindow with “SEL_KEYPRESS”, but that "event"
does never occur.

I can, however, successfully connect an FXLabel widget with
"SEL_LEFTBUTTONPRESS" and make the application quit when the user clicks on
the label. Oddly enough I cannot connect the FXLabel widget with
"SEL_CLICKED".

I have found a list of selector types here:
http://microtechnique.epfl.ch/~dgehrige/foxdoc/group__fxdefs__0.html#a0a193

So how can I make my application quit when any key is pressed?
Thanks for any help in advance.

Kind Regards,

-Lars

Lars M. wrote:

I want my FXRuby application to close when the user hits any key (the
application does not require any other interaction at all).

I tried to connect the FXMainWindow with “SEL_KEYPRESS”, but that “event”
does never occur.

Widgets that the user typically interacts with, like text fields and
push buttons, are enabled for events by default. In other words, they
are “listening” for user interface events like key presses and mouse
buttons clicks. Other widgets, like the main window, are not enabled by
default, but can be enabled by calling the enable() method. So if you
want your application’s main window to be sensitive to key presses in
general, you’ll need to enable it first, e.g.

 myMainWindow = FXMainWindow.new(...)
 myMainWindow.enable

I can, however, successfully connect an FXLabel widget with
“SEL_LEFTBUTTONPRESS” and make the application quit when the user clicks on
the label. Oddly enough I cannot connect the FXLabel widget with
“SEL_CLICKED”.

For a list of all the messages that widgets might forward to their
message targets, see this note:

 http://www.knology.net/~lyle/fox/1.0/FoxMessages.pdf.gz

Note that inheritance comes into play for this list; i.e. since a
FXLabel is-a FXWindow, it will forward SEL_LEFTBUTTONPRESS messages to
its message target since FXWindow does. On the other hand, only a few
widgets send SEL_CLICKED to their message targets, and FXLabel (and its
ancestors) are not among those.

So how can I make my application quit when any key is pressed?

 myMainWindow.enable
 myMainWindow.connect(SEL_KEYPRESS) { |sender, sel, event|
   # some key was pressed, so quit
   exit
 }

Hope this helps,

Lyle

Lyle, awesome, detailed answer. Somehow I am not compatible with Fox’s
documentation; What especially bothers me is that not every (I suspect no)
virtual method of a child class is linked with the corresponding parent
method. In contrast, QT’s documentation is extremely easy to understand and
extremely well formatted/linked. I would have never suspected that I have to
enable widgets first.

Thanks again. Using FXRuby is extreme fun.

-Lars

“Lars M.” lars-m@gmx.net wrote in message
news:av4du0$t1c$04$1@news.t-online.com

Hi,

I want my FXRuby application to close when the user hits any key (the
application does not require any other interaction at all).

I tried to connect the FXMainWindow with “SEL_KEYPRESS”, but that “event”
does never occur.

I can, however, successfully connect an FXLabel widget with
“SEL_LEFTBUTTONPRESS” and make the application quit when the user clicks
on
the label. Oddly enough I cannot connect the FXLabel widget with
“SEL_CLICKED”.

I have found a list of selector types here:

http://microtechnique.epfl.ch/~dgehrige/foxdoc/group__fxdefs__0.html#a0a193

···

So how can I make my application quit when any key is pressed?
Thanks for any help in advance.

Kind Regards,

-Lars