EventBox key press event

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

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