# FXRuby - handling Alt+F4

**URL:** <https://rubytalk.org/t/fxruby-handling-alt-f4/16320>\
**Category:** ruby-talk\
**Created:** [7 February 2005 18:17 UTC](https://rubytalk.org/t/fxruby-handling-alt-f4/16320 "2005-02-07T18:17:14Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chris\_Morris2](https://avatars.discourse-cdn.com/v4/letter/c/c67d28/32.png) [@Chris\_Morris2](https://rubytalk.org/u/Chris_Morris2)\
**Post date:** [7 February 2005 18:17 UTC](https://rubytalk.org/t/fxruby-handling-alt-f4/16320/1 "2005-02-07T18:17:14Z")

</div>

I'm trying to properly write a way to capture an Alt+F4 keystroke, and  
I'm not finding the right constant for the Alt key. Here's what I've  
currently got, and it works, but obviously isn't the 'correct' way to  
&& out the Alt key from the evt.state:

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (evt.state == 24) && (evt.code == KEY\_F4)  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;exit  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;...  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end

> **···**
>
> --  
> Chris  
> [http://clabs.org](http://clabs.org)

---

<div class="post-metadata">

**Author:** ![Stephan\_Kamper3](https://avatars.discourse-cdn.com/v4/letter/s/d9b06d/32.png) [@Stephan\_Kamper3](https://rubytalk.org/u/Stephan_Kamper3)\
**Post date:** [7 February 2005 19:25 UTC](https://rubytalk.org/t/fxruby-handling-alt-f4/16320/2 "2005-02-07T19:25:12Z")

</div>

Chris Morris wrote:

> I'm trying to properly write a way to capture an Alt+F4 keystroke, and  
> I'm not finding the right constant for the Alt key. Here's what I've  
> currently got, and it works, but obviously isn't the 'correct' way to  
> && out the Alt key from the evt.state:
> 
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (evt.state == 24) && (evt.code == KEY\_F4)  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;exit  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;...  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end

I did it by writing this:

menu\_bar = FXMenubar.new( self, LAYOUT\_SIDE\_TOP | LAYOUT\_FILL\_X )

file\_menu = FXMenuPane.new( self )  
FXMenuCommand.new( fileMenu, "&Quit\tALT-F4", nil, app, FXApp::ID\_QUIT )

I'm sure there are ways to close an application without having a menu bar. Lyle?

Happy rubying

Stephan

---

<div class="post-metadata">

**Author:** ![Lyle\_Johnson3](https://avatars.discourse-cdn.com/v4/letter/l/c89c15/32.png) [@Lyle\_Johnson3](https://rubytalk.org/u/Lyle_Johnson3)\
**Post date:** [7 February 2005 19:31 UTC](https://rubytalk.org/t/fxruby-handling-alt-f4/16320/3 "2005-02-07T19:31:30Z")

</div>

On Tue, 8 Feb 2005 04:25:12 +0900, Stephan Kämper

> I'm sure there are ways to close an application without having a menu  
> bar. Lyle?

I haven't tried this, but what happens if you just add the accelerator  
directly to the main window's accelerator table, i.e.

&nbsp;&nbsp;&nbsp;&nbsp;mainWindow.addAccel(fxparseAccel("Alt+F4"), app, FXApp::ID\_QUIT))

Hope this helps,

Lyle

---

<div class="post-metadata">

**Author:** ![Lyle\_Johnson3](https://avatars.discourse-cdn.com/v4/letter/l/c89c15/32.png) [@Lyle\_Johnson3](https://rubytalk.org/u/Lyle_Johnson3)\
**Post date:** [17 February 2005 14:16 UTC](https://rubytalk.org/t/fxruby-handling-alt-f4/16320/4 "2005-02-17T14:16:09Z")

</div>

I think you must be using FXRuby 1.0, and I was using the FXRuby 1.2  
"spelling". Try "fxparseaccel" (with all lowercase letters) instead.

> **···**
>
> On Sun, 13 Feb 2005 21:23:15 -0600, Chris Morris \<the.chrismo@gmail.com\> wrote:
> 
> > fxparseAccel failed -- not in scope or what-have-you -- what requires  
> > do I need to be able to use this? (Or is it a version problem? Not  
> > sure what version I'm using).
