This event class contains information about key press and release events.
The main information carried by this event is the key being pressed or released. It can be accessed using either
While both of these functions can be used with the events of
However for the key down and up events the returned key code will instead be
Notice that the first rule applies to all Unicode letters, not just the usual Latin-1 ones. However for non-Latin-1 letters only
To summarize: you should handle
Note: Not all key down events may be generated by the user. As an example,
Another difference between key and char events is that another kind of translation is done for the latter ones when the Control key is pressed: char events for ASCII letters in this case carry codes corresponding to the ASCII value of Ctrl-Latter, i.e. 1 for Ctrl-A, 2 for Ctrl-B and so on until 26 for Ctrl-Z. This is convenient for terminal-like applications and can be completely ignored by all the other ones (if you need to handle Ctrl-A it is probably a better idea to use the key event rather than the char one). Notice that currently no translation is done for the presses of [,
Finally, modifier keys only generate key events but no char events at all. The modifiers keys are
Modifier keys events are special in one additional aspect: usually the keyboard state associated with a key press is well defined, e.g.
Note: If a key down (
Note: If a key is maintained in a pressed state, you will typically get a lot of (automatically generated) key down events but only one key up one at the end when the key is released so it is wrong to assume that there is one up event corresponding to each down one.
Note: For Windows programmers: The key and char events in wxWidgets are similar to but slightly different from Windows
See:
This class is derived (and can use functions) from:
wxWidgets docs:
Use
Returns true if the Alt key is pressed.
Notice that
Returns true if the key used for command accelerators is pressed.
Same as
Notice that
Returns true if the Control key or Apple/Command key under macOS is pressed.
This function doesn't distinguish between right and left control keys.
Notice that
Returns the key code of the key that generated this event.
ASCII symbols return normal ASCII values, while events from special keys such as "left cursor arrow" (
Note that this method returns a meaningful value only for special non-alphanumeric keys or if the user entered a Latin-1 character (this includes ASCII and the accented letters found in Western European languages but not letters of other alphabets such as e.g. Cyrillic). Otherwise it simply method returns
Using
Return the bit mask of all pressed modifier keys.
The return value is a combination of
Notice that this function is easier to use correctly than, for example,
and forgetting to do it can result in serious program bugs (e.g. program not working with European keyboard layout where
with this function.
Obtains the position (in client coordinates) at which the key was pressed.
Notice that under most platforms this position is simply the current mouse pointer position and has no special relationship to the key event itself.
Returns the raw key code for this event.
The flags are platform-dependent and should only be used if the functionality provided by other
Under MSW, the raw key code is the value of
Under GTK, the raw key code is the
Under macOS, the raw key code is the
Note: Currently the raw key codes are not supported by all ports, use #ifdef wxHAS_RAW_KEY_CODES to determine if this feature is available.
Returns the low level key flags for this event.
The flags are platform-dependent and should only be used if the functionality provided by other
Under MSW, the raw flags are just the value of
Under GTK, the raw flags contain the
Under macOS, the raw flags contain the modifiers state.
Note: Currently the raw key flags are not supported by all ports, use #ifdef wxHAS_RAW_KEY_CODES to determine if this feature is available.
Returns the Unicode character corresponding to this key event.
If the key pressed doesn't have any character value (e.g. a cursor key) this method will return
This function is only available in Unicode build, i.e. when
Returns the X position (in client coordinates) of the event.
See:
Returns the Y position (in client coordinates) of the event.
See:
Returns true if Control or Alt are pressed.
Checks if Control, Alt or, under macOS only, Command key are pressed (notice that the real Control key is still taken into account under OS X too).
This method returns false if only Shift is pressed for compatibility reasons and also because pressing Shift usually doesn't change the interpretation of key events, see
Returns true if the Meta/Windows/Apple key is pressed.
This function tests the state of the key traditionally called Meta under Unix systems, Windows keys under MSW Notice that
See:
Returns true if the Shift key is pressed.
This function doesn't distinguish between right and left shift keys.
Notice that