I am trying to test my widgets automatically, but I don´t know how
to send a key event programmatically to a window.
Suposse i want to imitate the sending of a keystroke to a text
control. I would like to say something like
...
SendKey(txtCtrl, keyCode=48, altDown=0, shitDown=0 ,...)
...
As was mentioned you can do
wxPostEvent(window.GetEventHandler(), event)
and the event will be sent to the window in idle time, or you can do
window.GetEventHandler().ProcessEvent(event)
and the event will be processed immediately. There are some complications
though... As mentioned in the last message the public data members of
wxKeyEvent (and wxMouseEvent) aren't currently exposed to wxPython, only the
methods.
Also, for some (most?) event types artificially generating and sending an
event won't actually effect the window. You'll be able to test your event
handlers, but the default behaviour won't happen. For an example look at
what happens when a key event happens naturally on MSW:
1. Windows sends a WM_CHAR message to a wxWindow
2. the wxWindow catches the message and turns it into a wxKeyEvent
3. the event is sent with GetEventHandler()->ProcessEvent(event) which looks
for an event handler bound with EVT_CHAR
4. if the event was not caught or the handler called event.Skip() then the
original message is passed on to the window's default WndProc where is does
things like adding a character to a text control
When you artificially generate and send an event you can simulate up to #3,
but when ProcessEvent returns there is no way to send the message on to the
window for default processing. Even if there was a way it would be
drastically
different on different platforms.
···
--
Robin Dunn
Software Craftsman
robin@AllDunn.com
http://wxpython.org Java give you jitters?
http://wxpros.com Relax with wxPython!