Forum: wxRuby Can't capture key events

D515bf701f381b9331d802ed763fe0bc?d=identicon&s=25 Chris Williams (ceedub)
on 2010-02-25 22:20
In the following example code, there is no response to pressing any key.
The mouse button does produce the desired result:

require 'rubygems'
require 'wx'

class EventFrame < Wx::Frame
    def initialize()
        super(nil, -1, "Event Frame")
  panel = Wx::Panel.new(self)
        panel.evt_left_down {|event| puts "Left mouse key clicked"}
        panel.evt_key_down{|event|  puts "Key clicked"}
        show()
    end
end


class MyApp < Wx::App
    def on_init
        EventFrame.new()
    end
end

MyApp.new.main_loop

...

This is wxruby 2.0.1 on Ubuntu 9.10. I have also tried evt_key_up and
evt_char.

Any ideas?

Thanks,
Chris
D515bf701f381b9331d802ed763fe0bc?d=identicon&s=25 Chris Williams (ceedub)
on 2010-02-25 22:53
Chris Williams wrote:
> In the following example code, there is no response to pressing any key.


I found an answer. It works if I specifically give the panel focus
(panel.set_focus).
This topic is locked and can not be replied to.