# Catch all key events in frame?

**URL:** <https://www.ruby-forum.com/t/catch-all-key-events-in-frame/141662>\
**Category:** wxRuby\
**Created:** [June 28, 2008, 7:23pm UTC](https://www.ruby-forum.com/t/catch-all-key-events-in-frame/141662 "2008-06-28T19:23:55Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Albin\_Holmgren](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/85f322/32.png) [@Albin\_Holmgren](https://www.ruby-forum.com/u/Albin_Holmgren)\
**Post date:** [June 28, 2008, 7:23pm UTC](https://www.ruby-forum.com/t/catch-all-key-events-in-frame/141662/1 "2008-06-28T19:23:55Z")

</div>

Hi.

How do I best capture _all_ key events in a frame. Specifically: In  
Albuin I  
want to delete selected songs in the playlist when the user presses  
‘del’ -  
no matter what control in the frame happens to be in focused atm. What  
event  
should I bind to and to which control?

(as a side note, the latest svn of albuin fixed the alexs’ problem with  
sequel-2.x - never, ever, use depreched methods… 🙂

Thanks,  
Albin Holmgren

---

<div class="post-metadata">

**Author:** ![Albin\_Holmgren](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/85f322/32.png) [@Albin\_Holmgren](https://www.ruby-forum.com/u/Albin_Holmgren)\
**Post date:** [June 28, 2008, 11:52pm UTC](https://www.ruby-forum.com/t/catch-all-key-events-in-frame/141662/2 "2008-06-28T23:52:16Z")

</div>

Hi Albin

Albin Holmgren wrote:

> How do I best capture _all_ key events in a frame. Specifically: In  
> Albuin I want to delete selected songs in the playlist when the user  
> presses ‘del’ - no matter what control in the frame happens to be in  
> focused atm. What event should I bind to and to which control?  
> For that sort of thing you could use an accelerator table, which creates  
> keyboard shortcuts for menu items. This example makes the ‘backspace’  
> key a shortcut for the Wx::ID\_EXIT menu item (assuming self is a  
> Wx::Frame)

```
tbl = Wx::AcceleratorTable.new [Wx::ACCEL_NORMAL, Wx::K_BACK,

```

Wx::ID\_EXIT ]  
self.accelerator\_table = tbl

The code for del is Wx::K\_DEL. As an aside, Mac laptops don’t generally  
have a ‘del’ key so it may not be the best choice for a shortcut.

> (as a side note, the latest svn of albuin fixed the alexs’ problem  
> with sequel-2.x - never, ever, use depreched methods… 🙂  
> Thanks; I’ll give it a whirl when I get a moment.

alex
