wxkeyeventthis event class contains information about keypress (character) events. notice that there are three different kinds of keyboard events in wxwidgets: key down and up events and char events. the difference between the first two is clear - the first corresponds to a key press and the second to a key release - otherwise they are identical. just note that if the key is maintained in a pressed state you will typically get a lot of (automatically generated) down events but only one up so it is wrong to assume that there is one up event corresponding to each down one. both key events provide untranslated key codes while the char event carries the translated one. the untranslated code for alphanumeric keys is always an upper case value. for the other keys it is one of wxk_xxx values from the keycodes table. the translated key is, in general, the character the user expects to appear as the result of the key combination when typing the text into a text entry zone, for example. a few examples to clarify this (all assume that caps lock is unpressed and the standard us keyboard): when the 'a' key is pressed, the key down event key code is equal to ascii a == 65. but the char event key code is ascii a == 97. on the other hand, if you press both shift and 'a' keys simultaneously , the key code in key down event will still be just 'a' while the char event key code parameter will now be 'a' as well. although in this simple case it is clear that the correct key code could be found in the key down event handler by checking the value returned by shiftdown(), in general you should use evt_char for this as for non-alphanumeric keys the translation is keyboard-layout dependent and can only be done properly by the system itself. another kind of translation is done when the control key is pressed: for example, for ctrl-a key press the key down event still carries the same key code 'a' as usual but the char event will have key code of 1, the ascii value of this key combination. you may discover how the other keys on your system behave interactively by running the text wxwidgets sample and pressing some keys in any of the text controls shown in it. note: if a key down (evt_key_down) event is caught and the event handler does not call event.skip() then the corresponding char event (evt_char) will not happen. this is by design and enables the programs that handle both types of events to be a bit simpler. note for windows programmers: the key and char events in wxwidgets are similar to but slightly different from windows wm_keydown and wm_char events. in particular, alt-x combination will generate a char event in wxwidgets (unless it is used as an accelerator). tip: be sure to call event.skip() for events that you don't process in key event function, otherwise menu shortcuts may cease to work under windows. derived from include files <wx/event.h> event table macros to process a key event, use these event handler macros to direct input to member functions that take a wxkeyevent argument.
wxkeyevent::m_altdown
wxkeyevent::m_altdownbool m_altdown deprecated: please use getmodifiers instead! true if the alt key is pressed down.
wxkeyevent::m_controldownbool m_controldown deprecated: please use getmodifiers instead! true if control is pressed down.
wxkeyevent::m_keycodelong m_keycode deprecated: please use getkeycode instead! virtual keycode. see keycodes for a list of identifiers.
wxkeyevent::m_metadownbool m_metadown deprecated: please use getmodifiers instead! true if the meta key is pressed down.
wxkeyevent::m_shiftdownbool m_shiftdown deprecated: please use getmodifiers instead! true if shift is pressed down.
wxkeyevent::m_xint m_x deprecated: please use getx instead! x position of the event.
wxkeyevent::m_yint m_y deprecated: please use gety instead! y position of the event.
wxkeyevent::wxkeyeventwxkeyevent(wxtype keyeventtype) constructor. currently, the only valid event types are wxevt_char and wxevt_char_hook.
wxkeyevent::altdownbool altdown() const returns true if the alt key was down at the time of the key event. notice that getmodifiers is easier to use correctly than this function so you should consider using it in new code.
wxkeyevent::cmddownbool cmddown() const cmd is a pseudo key which is the same as control for pc and unix platforms but the special apple (a.k.a as command) key under macs: it makes often sense to use it instead of, say, controldown() because cmd key is used for the same thing under mac as ctrl elsewhere (but ctrl still exists, just not used for this purpose under mac). so for non-mac platforms this is the same as controldown() and under mac this is the same as metadown().
wxkeyevent::controldownbool controldown() const returns true if the control key was down at the time of the key event. notice that getmodifiers is easier to use correctly than this function so you should consider using it in new code.
wxkeyevent::getkeycodeint getkeycode() const returns the virtual key code. ascii events return normal ascii values, while non-ascii events return values such as wxk_left for the left cursor key. see keycodes for a full list of the virtual key codes. note that in unicode build, the returned value is meaningful only if the user entered a character that can be represented in current locale's default charset. you can obtain the corresponding unicode character using getunicodekey.
wxkeyevent::getmodifiersint getmodifiers() const return the bitmask of modifier keys which were pressed when this event happened. see key modifier constants for the full list of modifiers. notice that this function is easier to use correctly than, for example, controldown because when using the latter you also have to remember to test that none of the other modifiers is pressed:
if ( controldown() && !altdown() && !shiftdown() && !metadown() ) ... handle ctrl-xxx ...and forgetting to do it can result in serious program bugs (e.g. program not working with european keyboard layout where altgr key which is seen by the program as combination of ctrl and alt is used). on the other hand, you can simply write
if ( getmodifiers() == wxmod_control ) ... handle ctrl-xxx ...with this function.
wxkeyevent::getpositionwxpoint getposition() const void getposition(long *x, long *y) const obtains the position (in client coordinates) at which the key was pressed.
wxkeyevent::getrawkeycodewxuint32 getrawkeycode() const returns the raw key code for this event. this is a platform-dependent scan code which should only be used in advanced applications. nb: currently the raw key codes are not supported by all ports, use #ifdef wxhas_raw_key_codes to determine if this feature is available.
wxkeyevent::getrawkeyflagswxuint32 getrawkeyflags() const returns the low level key flags for this event. the flags are platform-dependent and should only be used in advanced applications. nb: currently the raw key flags are not supported by all ports, use #ifdef wxhas_raw_key_codes to determine if this feature is available.
wxkeyevent::getunicodekeywxchar getunicodekey() const returns the unicode character corresponding to this key event. this function is only available in unicode build, i.e. when wxuse_unicode is 1.
wxkeyevent::getxlong getx() const returns the x position (in client coordinates) of the event.
wxkeyevent::getylong gety() const returns the y (in client coordinates) position of the event.
wxkeyevent::hasmodifiersbool hasmodifiers() const returns true if either ctrl or alt keys was down at the time of the key event. note that this function does not take into account neither shift nor meta key states (the reason for ignoring the latter is that it is common for numlock key to be configured as meta under x but the key presses even while numlock is on should be still processed normally).
wxkeyevent::metadownbool metadown() const returns true if the meta key was down at the time of the key event. notice that getmodifiers is easier to use correctly than this function so you should consider using it in new code.
wxkeyevent::shiftdownbool shiftdown() const returns true if the shift key was down at the time of the key event. notice that getmodifiers is easier to use correctly than this function so you should consider using it in new code.
|