#include <wx/event.h>
This event allows to change the default logic for determining whether a key press should be processed as an accelerator or not.
It is generated when a key corresponding to an accelerator defined by the application (either explicitly, in a wxAcceleratorTable associated with the window using wxWindow::SetAcceleratorTable(), or implicitly, by specifying it as part of a label of a wxMenuItem in the wxMenuBar associated with the wxFrame containing this window) is pressed and allows to decide whether the accelerator should be used or whether the key should be handled by the window having the focus as if no accelerators using it were defined.
By default, the accelerator is used and the window doesn't receive any key events for this key press. If a handler for this event is found and it doesn't do anything and, in particular, doesn't call wxEvent::Skip(), the accelerator is not used and the window having the focus receives the normal key events for this key press. And if the handler calls UseAccelerator(), the accelerator is used even if it wouldn't have been used by default because the focused window would use the key corresponding to it for its own needs, e.g. wxTextCtrl overrides wxWindow::ClaimsKeyBeforeAccelerator() to use Ctrl-C for copying the selected text but handling this event and calling UseAccelerator() allows the application to use this key combination for some application-defined functionality:
Note that this event is only generated for the keys corresponding to the accelerators defined by the application and not for all keys. It is sent to the window having the focus after wxEVT_CHAR_HOOK, which still takes priority over everything else, and, similarly to it, is propagated to all the parents of this window, up to the top level one, which allows to handle it in the frame containing the control having the focus.
The following event handler macros redirect the events to member function handlers 'func' with prototypes like:
Event macros:
Public Member Functions | |
| int | GetCommand () const |
| Return the ID of the command which would be generated by the accelerator. | |
| wxMenuItem * | GetMenuItem () const |
| Return the menu item using this accelerator. | |
| void | UseAccelerator () |
| Use the accelerator unconditionally. | |
| Public Member Functions inherited from wxKeyEvent | |
| wxKeyEvent (wxEventType keyEventType=wxEVT_NULL) | |
| Constructor. | |
| int | GetKeyCode () const |
| Returns the key code of the key that generated this event. | |
| bool | IsKeyInCategory (int category) const |
| Returns true if the key is in the given key category. | |
| bool | IsAutoRepeat () const |
| Returns true if this event is an auto-repeat of the key, false if this is the initial key press. | |
| wxUint32 | GetRawKeyCode () const |
| Returns the raw key code for this event. | |
| wxUint32 | GetRawKeyFlags () const |
| Returns the low level key flags for this event. | |
| wxUniChar | GetUnicodeChar () const |
| Returns the Unicode character corresponding to this key event. | |
| wxChar | GetUnicodeKey () const |
| Returns the Unicode character corresponding to this key event. | |
| wxCoord | GetX () const |
| Returns the X position (in client coordinates) of the event. | |
| wxCoord | GetY () const |
| Returns the Y position (in client coordinates) of the event. | |
| void | DoAllowNextEvent () |
| Allow normal key events generation. | |
| bool | IsNextEventAllowed () const |
| Returns true if DoAllowNextEvent() had been called, false by default. | |
| wxPoint | GetPosition () const |
| Obtains the position (in client coordinates) at which the key was pressed. | |
| void | GetPosition (wxCoord *x, wxCoord *y) const |
| Obtains the position (in client coordinates) at which the key was pressed. | |
| Public Member Functions inherited from wxEvent | |
| wxEvent (int id=0, wxEventType eventType=wxEVT_NULL) | |
| Constructor. | |
| virtual wxEvent * | Clone () const =0 |
| Returns a copy of the event. | |
| wxObject * | GetEventObject () const |
| Returns the object (usually a window) associated with the event, if any. | |
| wxEventType | GetEventType () const |
Returns the identifier of the given event type, such as wxEVT_BUTTON. | |
| virtual wxEventCategory | GetEventCategory () const |
| Returns a generic category for this event. | |
| int | GetId () const |
| Returns the identifier associated with this event, such as a button command id. | |
| wxObject * | GetEventUserData () const |
| Return the user data associated with a dynamically connected event handler. | |
| bool | GetSkipped () const |
| Returns true if the event handler should be skipped, false otherwise. | |
| long | GetTimestamp () const |
| Gets the timestamp for the event. | |
| bool | IsCommandEvent () const |
| Returns true if the event is or is derived from wxCommandEvent else it returns false. | |
| void | ResumePropagation (int propagationLevel) |
| Sets the propagation level to the given value (for example returned from an earlier call to wxEvent::StopPropagation). | |
| void | SetEventObject (wxObject *object) |
| Sets the originating object. | |
| void | SetEventType (wxEventType type) |
| Sets the event type. | |
| void | SetId (int id) |
| Sets the identifier associated with this event, such as a button command id. | |
| void | SetTimestamp (long timeStamp=0) |
| Sets the timestamp for the event. | |
| bool | ShouldPropagate () const |
| Test if this event should be propagated or not, i.e. if the propagation level is currently greater than 0. | |
| void | Skip (bool skip=true) |
| This method can be used inside an event handler to control whether further event handlers bound to this event will be called after the current one returns. | |
| int | StopPropagation () |
| Stop the event from propagating to its parent window. | |
| Public Member Functions inherited from wxObject | |
| wxObject () | |
| Default ctor; initializes to nullptr the internal reference data. | |
| wxObject (const wxObject &other) | |
| Copy ctor. | |
| virtual | ~wxObject () |
| Destructor. | |
| virtual wxClassInfo * | GetClassInfo () const |
| This virtual function is redefined for every class that requires run-time type information, when using the wxDECLARE_CLASS macro (or similar). | |
| wxObjectRefData * | GetRefData () const |
| Returns the wxObject::m_refData pointer, i.e. the data referenced by this object. | |
| bool | IsKindOf (const wxClassInfo *info) const |
| Determines whether this class is a subclass of (or the same class as) the given class. | |
| bool | IsSameAs (const wxObject &obj) const |
| Returns true if this object has the same data pointer as obj. | |
| void | Ref (const wxObject &clone) |
| Makes this object refer to the data in clone. | |
| void | SetRefData (wxObjectRefData *data) |
| Sets the wxObject::m_refData pointer. | |
| void | UnRef () |
| Decrements the reference count in the associated data, and if it is zero, deletes the data. | |
| void | UnShare () |
| This is the same of AllocExclusive() but this method is public. | |
| void | operator delete (void *buf) |
The delete operator is defined for debugging versions of the library only, when the identifier __WXDEBUG__ is defined. | |
| void * | operator new (size_t size, const wxString &filename=nullptr, int lineNum=0) |
The new operator is defined for debugging versions of the library only, when the identifier __WXDEBUG__ is defined. | |
| Public Member Functions inherited from wxKeyboardState | |
| wxKeyboardState (bool controlDown=false, bool shiftDown=false, bool altDown=false, bool metaDown=false) | |
| Constructor initializes the modifier key settings. | |
| int | GetModifiers () const |
| Return the bit mask of all pressed modifier keys. | |
| bool | HasAnyModifiers () const |
| Returns true if any modifiers at all are pressed. | |
| bool | HasModifiers () const |
| Returns true if Control or Alt are pressed. | |
| bool | ControlDown () const |
| Returns true if the Control key or Apple/Command key under macOS is pressed. | |
| bool | RawControlDown () const |
| Returns true if the Control key (also under macOS). | |
| bool | ShiftDown () const |
| Returns true if the Shift key is pressed. | |
| bool | MetaDown () const |
| Returns true if the Meta/Windows/Apple key is pressed. | |
| bool | AltDown () const |
| Returns true if the Alt key is pressed. | |
| bool | CmdDown () const |
| Returns true if the key used for command accelerators is pressed. | |
| void | SetControlDown (bool down) |
| void | SetRawControlDown (bool down) |
| void | SetShiftDown (bool down) |
| void | SetAltDown (bool down) |
| void | SetMetaDown (bool down) |
Additional Inherited Members | |
| Protected Member Functions inherited from wxObject | |
| void | AllocExclusive () |
| Ensure that this object's data is not shared with any other object. | |
| virtual wxObjectRefData * | CreateRefData () const |
| Creates a new instance of the wxObjectRefData-derived class specific to this object and returns it. | |
| virtual wxObjectRefData * | CloneRefData (const wxObjectRefData *data) const |
| Creates a new instance of the wxObjectRefData-derived class specific to this object and initializes it copying data. | |
| Protected Attributes inherited from wxEvent | |
| int | m_propagationLevel |
| Indicates how many levels the event can propagate. | |
| Protected Attributes inherited from wxObject | |
| wxObjectRefData * | m_refData |
| Pointer to an object which is the object's reference-counted data. | |
| int wxAcceleratorKeyEvent::GetCommand | ( | ) | const |
Return the ID of the command which would be generated by the accelerator.
For the accelerators coming from a menu item, this is the ID of this item, otherwise it is the one of the corresponding wxAcceleratorEntry.
| wxMenuItem * wxAcceleratorKeyEvent::GetMenuItem | ( | ) | const |
Return the menu item using this accelerator.
This function returns nullptr if the accelerator doesn't come from a menu item but from a wxAcceleratorTable.
| void wxAcceleratorKeyEvent::UseAccelerator | ( | ) |
Use the accelerator unconditionally.
Calling this function makes the accelerator work even for the keys reserved by the focused window, such as the keys used for editing the text in the text entry controls.
This only has an effect if the event is not skipped by the handler.