@beginEventTable{wxKeyEvent}
@event{EVT_KEY_DOWN(func)}
- Process a @c wxEVT_KEY_DOWN event (any key has been pressed).
+ Process a @c wxEVT_KEY_DOWN event (any key has been pressed). If this
+ event is handled and not skipped, @c wxEVT_CHAR will not be generated
+ at all for this key press (but @c wxEVT_KEY_UP will be).
@event{EVT_KEY_UP(func)}
Process a @c wxEVT_KEY_UP event (any key has been released).
@event{EVT_CHAR(func)}
or wxApp global object if there is no active window before any other
keyboard events are generated giving the parent window the opportunity
to intercept all the keyboard entry. If the event is handled, i.e. the
- handler doesn't call wxEvent::Skip(), no further keyboard events are
- generated. Notice that this event is not generated when the mouse is
+ handler doesn't call wxEvent::Skip(), neither @c wxEVT_KEY_DOWN nor @c
+ wxEVT_CHAR events will be generated (although @c wxEVT_KEY_UP still
+ will be). Notice that this event is not generated when the mouse is
captured as it is considered that the window which has the capture
should receive all the keyboard events too without allowing its parent
wxTopLevelWindow to interfere with their processing.
namespace
{
-// Send wxEVT_CHAR_HOOK event to the parent of the window and if it wasn't
-// processed, send wxEVT_CHAR to the window itself. Return true if either of
-// them was handled.
-bool
-SendCharHookAndCharEvents(const wxKeyEvent& event, wxWindow *win)
+// Send wxEVT_CHAR_HOOK event to the parent of the window and return true only
+// if it was processed (and not skipped).
+bool SendCharHookEvent(const wxKeyEvent& event, wxWindow *win)
{
// wxEVT_CHAR_HOOK must be sent to the top level parent window to allow it
// to handle key events in all of its children unless the mouse is captured
}
}
- // As above, make a copy of the event first.
- wxKeyEvent eventChar(event);
- eventChar.SetEventType(wxEVT_CHAR);
- return win->HandleWindowEvent(eventChar);
+ return false;
}
} // anonymous namespace
if( wxTranslateGTKKeyEventToWx(event, win, gdk_event) )
{
+ // Send the CHAR_HOOK event first
+ if ( SendCharHookEvent(event, win) )
+ {
+ // Don't do anything at all with this event any more.
+ return TRUE;
+ }
+
// Emit KEY_DOWN event
ret = win->HandleWindowEvent( event );
}
if ( key_code )
{
+ wxKeyEvent eventChar(wxEVT_CHAR, event);
+
wxLogTrace(TRACE_KEYS, wxT("Char event: %ld"), key_code);
- event.m_keyCode = key_code;
+ eventChar.m_keyCode = key_code;
// To conform to the docs we need to translate Ctrl-alpha
// characters to values in the range 1-26.
- if ( event.ControlDown() &&
+ if ( eventChar.ControlDown() &&
( wxIsLowerChar(key_code) || wxIsUpperChar(key_code) ))
{
if ( wxIsLowerChar(key_code) )
- event.m_keyCode = key_code - 'a' + 1;
+ eventChar.m_keyCode = key_code - 'a' + 1;
if ( wxIsUpperChar(key_code) )
- event.m_keyCode = key_code - 'A' + 1;
+ eventChar.m_keyCode = key_code - 'A' + 1;
#if wxUSE_UNICODE
- event.m_uniChar = event.m_keyCode;
+ eventChar.m_uniChar = event.m_keyCode;
#endif
}
- ret = SendCharHookAndCharEvents(event, win);
+ ret = win->HandleWindowEvent(eventChar);
}
}
const gchar *str,
wxWindow *window)
{
- wxKeyEvent event( wxEVT_KEY_DOWN );
+ wxKeyEvent event( wxEVT_CHAR );
// take modifiers, cursor position, timestamp etc. from the last
// key_press_event that was fed into Input Method:
#endif
}
- SendCharHookAndCharEvents(event, window);
+ window->HandleWindowEvent(event);
}
}
}