# Can't capture key events

**URL:** <https://www.ruby-forum.com/t/cant-capture-key-events/184164>\
**Category:** wxRuby\
**Created:** [February 25, 2010, 10:20pm UTC](https://www.ruby-forum.com/t/cant-capture-key-events/184164 "2010-02-25T22:20:44Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![supasta](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ebca7d/32.png) [@supasta](https://www.ruby-forum.com/u/supasta)\
**Post date:** [February 25, 2010, 10:20pm UTC](https://www.ruby-forum.com/t/cant-capture-key-events/184164/1 "2010-02-25T22:20:44Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![supasta](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ebca7d/32.png) [@supasta](https://www.ruby-forum.com/u/supasta)\
**Post date:** [February 25, 2010, 10:53pm UTC](https://www.ruby-forum.com/t/cant-capture-key-events/184164/2 "2010-02-25T22:53:58Z")

</div>

Chris W. 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).
