# Need help with navigation key events

**URL:** <https://www.ruby-forum.com/t/need-help-with-navigation-key-events/195168>\
**Category:** wxRuby\
**Created:** [September 18, 2010, 12:11am UTC](https://www.ruby-forum.com/t/need-help-with-navigation-key-events/195168 "2010-09-18T00:11:09Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![w\_barnes](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/f08c70/32.png) [@w\_barnes](https://www.ruby-forum.com/u/w_barnes)\
**Post date:** [September 18, 2010, 12:11am UTC](https://www.ruby-forum.com/t/need-help-with-navigation-key-events/195168/1 "2010-09-18T00:11:09Z")

</div>

Hello,

I’m having some trouble figuring out how to process navigation key  
events. I  
added the following test code to my dialog box:

def initialize( … )

evt\_navigation\_key(:on\_navigation\_key)

end

def on\_navigation\_key(event)  
puts “–tab pressed–”  
puts " event object: " + event.get\_event\_object.inspect  
obj = event.get\_current\_focus  
if obj  
puts " current focus: " + obj.inspect  
else  
puts " event.get\_current\_focus returned nil"  
puts " current focus: " + Wx::Window.find\_focus.inspect  
end

```
  event.skip

```

end

When testing the dialog box (which subclasses Wx::Dialog) there are no  
messages  
when tabbing from a text control. All other controls generate the  
expected  
messages. I am able however to tab through all controls in the correct  
order  
both forward and back.

All my controls except for a checkbox are grouped in static boxes. I  
have tried  
doing “xxxx.evt\_navigation\_key { |event| on\_navigation\_key(event) }” for  
the  
text boxes as well as the static boxes that contain them to no effect.

I’ve also noticed unusual behavior too. When tabbing into a radio box,  
there is  
no visual indication that it has the focus if the text control that  
precedes it  
is enabled. If the text control is disabled then it works fine. Also,  
when doing  
a shift+tab to navigate backwards, it will first go forward one control  
then  
start going backwards. Lastly, two navigation events with the same  
output are  
generated when cycling from the last control back to the first.

How do I get the navigation events to work properly and how can I  
capture  
navigation events when a text control has the focus?

Some additional info: I’m using Windows XP SP3, all controls and static  
boxes  
are children of the dialog box, all text controls are single line with  
the  
TE\_RICH window style.

TIA,  
Walter

---

<div class="post-metadata">

**Author:** ![w\_barnes](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/f08c70/32.png) [@w\_barnes](https://www.ruby-forum.com/u/w_barnes)\
**Post date:** [September 18, 2010, 6:25am UTC](https://www.ruby-forum.com/t/need-help-with-navigation-key-events/195168/2 "2010-09-18T06:25:41Z")

</div>

never mind, looks like I fixed it 🙂

Problem was that I needed to place all my controls in a panel. For some  
reason,  
panel.evt\_navigation\_key works but dialog.evt\_navigation\_key does not.  
This also  
fixed all the weird behavior I mentioned below too.

I am curious though… what is the difference between handling  
navigation events  
coming from a panel and handling the same type of events coming from a  
dialog?

Thanks,  
Walter

* * *

From: Walter B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
To: wxRuby U. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
Sent: Fri, September 17, 2010 2:46:35 PM  
Subject: [wxruby-users] need help with navigation key events

Hello,

I’m having some trouble figuring out how to process navigation key  
events. I  
added the following test code to my dialog box:

def initialize( … )

evt\_navigation\_key(:on\_navigation\_key)

end

def on\_navigation\_key(event)  
puts “–tab pressed–”  
puts " event object: " + event.get\_event\_object.inspect  
obj = event.get\_current\_focus  
if obj  
puts " current focus: " + obj.inspect  
else  
puts " event.get\_current\_focus returned nil"  
puts " current focus: " + Wx::Window.find\_focus.inspect  
end

```
  event.skip

```

end

When testing the dialog box (which subclasses Wx::Dialog) there are no  
messages  
when tabbing from a text control. All other controls generate the  
expected  
messages. I am able however to tab through all controls in the correct  
order  
both forward and back.

All my controls except for a checkbox are grouped in static boxes. I  
have tried  
doing “xxxx.evt\_navigation\_key { |event| on\_navigation\_key(event) }” for  
the  
text boxes as well as the static boxes that contain them to no effect.

I’ve also noticed unusual behavior too. When tabbing into a radio box,  
there is  
no visual indication that it has the focus if the text control that  
precedes it  
is enabled. If the text control is disabled then it works fine. Also,  
when doing  
a shift+tab to navigate backwards, it will first go forward one control  
then  
start going backwards. Lastly, two navigation events with the same  
output are  
generated when cycling from the last control back to the first.

How do I get the navigation events to work properly and how can I  
capture  
navigation events when a text control has the focus?

Some additional info: I’m using Windows XP SP3, all controls and static  
boxes  
are children of the dialog box, all text controls are single line with  
the  
TE\_RICH window style.

TIA,  
Walter
