wxFrame and OnKey()

Is it possible to bind keystrokes for a (window derived from) wxFrame? I have
a class derived from wxFrame, and provide a new version of OnKey(), but the
bindings don't seem to work (i.e., routine is not executed when keys pressed).

Perhaps I have a misconception about how wxFrame behaves/fits into the scheme
of things. Could someone then tell me how I can get what I'm trying to
achieve? I have a bunch of wxFrames up, and I want a given keystroke (e.g.
'q') to trigger some given function (e.g. OnKey() which contains
"sys.exit(0)") when the key is pressed while a given wxFrame has focus.

···

--
Maciej Kalisiak "A witty saying proves nothing." -- Fransua Voltaire
mac@dgp.utoronto.ca
www.dgp.utoronto.ca/~mac GE/CS d- s++:+ a- C++(+++) ULAI++ P+++ L+++ E+++ W++
                          N- !w--- t+ !X-- R+ tv-- b+>++++ e>+++>++++ r+++

Well, the thing is that if you do it with a simple key-binding, you're going to need to do it for every control/window in the frame to be sure you get the event. What you _probably_ want is a wxAcceleratorTable bound to your frame.

BTW, missed you at the PyGTA meeting.

HTH,
Mike

Maciej Kalisiak wrote:

···

Is it possible to bind keystrokes for a (window derived from) wxFrame? I have
a class derived from wxFrame, and provide a new version of OnKey(), but the
bindings don't seem to work (i.e., routine is not executed when keys pressed).

Perhaps I have a misconception about how wxFrame behaves/fits into the scheme
of things. Could someone then tell me how I can get what I'm trying to
achieve? I have a bunch of wxFrames up, and I want a given keystroke (e.g.
'q') to trigger some given function (e.g. OnKey() which contains
"sys.exit(0)") when the key is pressed while a given wxFrame has focus.

--
_______________________________________
  Mike C. Fletcher
  Designer, VR Plumber, Coder
  http://members.rogers.com/mcfletch/

Well, the thing is that if you do it with a simple key-binding, you're
going to need to do it for every control/window in the frame to be sure
you get the event. What you _probably_ want is a wxAcceleratorTable
bound to your frame.

Ahhh... looks very promising, will try it out. Thanks.

BTW, missed you at the PyGTA meeting.

Alas, only later did I notice that the meeting is held sort of late in the
evening for me... I live up in Markham... long commute home, and by then I will
have to use the local transit... so home by midnight or later. Ugh. I'll try
to figure something out for next time.

···

On Wed, Feb 26, 2003 at 03:44:06PM -0500, Mike C. Fletcher wrote:

--
"It is dangerous to be right when the government is wrong."
        -- Voltaire

Hmm, I tried this, and I think it's a bit better, but one large problem
remains: the accelerator only seems to work after I first click in the client
area of the frame (the frame in question contains a notebook with a few pages,
if it matters; I have to click on the notebook first). If I try the key combo
right after the application starts up, nothing happens. I tried SetFocus() on
the wxFrame, but that doesn't help. What is so magical about this first click?

···

On Wed, Feb 26, 2003 at 03:44:06PM -0500, Mike C. Fletcher wrote:

What you _probably_ want is a wxAcceleratorTable bound to your frame.

--
Two wrongs don't make a right -- but three lefts do.