# EventBox key press event

**URL:** <https://www.ruby-forum.com/t/eventbox-key-press-event/208770>\
**Category:** Ruby-Gnome 2\
**Created:** [June 26, 2011, 5:32pm UTC](https://www.ruby-forum.com/t/eventbox-key-press-event/208770 "2011-06-26T17:32:54Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![dubstep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/cdc98d/32.png) [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Post date:** [June 26, 2011, 5:32pm UTC](https://www.ruby-forum.com/t/eventbox-key-press-event/208770/1 "2011-06-26T17:32:54Z")

</div>

Anyone have any ideas why this will not work  
been working and googling for hours

It works on Gtk::Window

require ‘gtk2’  
w = Gtk::Window.new  
eb = Gtk::EventBox.new  
w.add(eb)  
eb.add\_events(Gdk::Event::ALL\_EVENTS\_MASK)  
#eb.add\_events(Gdk::Event::KEY\_PRESS\_MASK)

eb.signal\_connect(‘key-press-event’) do |widg, event|  
puts ‘pressed’  
end

w.show\_all  
Gtk::main

Thanks In Advance  
brad

---

<div class="post-metadata">

**Author:** ![oshybrid](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/c68b51/32.png) [@oshybrid](https://www.ruby-forum.com/u/oshybrid)\
**Post date:** [August 1, 2011, 12:42pm UTC](https://www.ruby-forum.com/t/eventbox-key-press-event/208770/2 "2011-08-01T12:42:24Z")

</div>

Brad M. wrote in post #1007709:

> require ‘gtk2’  
> w = Gtk::Window.new  
> eb = Gtk::EventBox.new  
> w.add(eb)  
> eb.add\_events(Gdk::Event::ALL\_EVENTS\_MASK)  
> #eb.add\_events(Gdk::Event::KEY\_PRESS\_MASK)
> 
> eb.signal\_connect(‘key-press-event’) do |widg, event|  
> puts ‘pressed’  
> end
> 
> w.show\_all  
> Gtk::main

The point of Gtk::EventBox is to enable capturing events on widgets  
which can’t. If you add the EventBox to Window, it is, more or less, non  
existing.

Try to add a child to your EventBox. For example :  
eb.add(Gtk::Button.new(“test”))

Try with a vbox, add 2 buttons, one in the event box, focus one or the  
other, and check event is only trigered with the one in the event box.

Simon
