[ Sorry again all for my double postings ]

Hi Steve,

Steve Cookson wrote:
So that's how it works! So if I want to detect tabbing out of a field to trigger validation, I use the lose focus event (EVT_KILL_FOCUS) on the control. But alt-tab (and I guess alt-esc etc) to another app also trigger it. How can I filter out alt-tab etc?

I know you've been tackling that for a few days, I'm still not sure I can help.

I don't think filtering keys is the way to go. I'd imagine it's not the actual keypress that generates a KILL_FOCUS, it's the /result/ of the keypress, if you get me. I think the best you could do with filtering key presses would be to disable alt-tab / program switching altogether when in that text field. That'd be in an event handler of a TextCtrl you subclassed yourself. You'd have to read up the wxWidgets docs [0], particularly wxKeyEvent and wxKeyCode to see what combination of EVT_KEY_DOWN, EVT_KEY_UP and/or EVT_CHAR you'd need to do what you need.

Looking around in the docs, I think a better way to do what you need would be using Wx::Window::FindFocus() [1] (in wxWidgets there's also a HasFocus() event that could be even more elegant but grep'ing for that doesn't show it anywhere in the Wx-0.91 source; maybe someone could correct me on that).

Could you just have something at the start of your EVT_KILL_FOCUS handler like this?

if ( Wx::Window::FindFocus ne $self->{nextCtrlByTab} ) { return; }

Or conceivably just if ( FindFocus == NULL ) if it returns null when focus has moved out of the program.

What do you think, workable?

-- Ryan



[0] http://docs.wxwidgets.org/trunk/

[1] http://docs.wxwidgets.org/trunk/classwx_window.html#777258379a3eef1b0530f12db6b77cab

Reply via email to