Provides methods for testing the state of the keyboard modifier keys.
This class is used as a base class of KeyEvent and MouseState and, hence, indirectly, of MouseEvent, so its methods may be used to get information about the modifier keys which were pressed when the event occurred.
This class is implemented entirely inline in </kbdstate.h> and thus has no linking requirements.
See also
__init__ | Constructor initializes the modifier key settings. |
AltDown | Returns True if the Alt key is pressed. |
CmdDown | Returns True if the key used for command accelerators is pressed. |
ControlDown | Returns True if the Control key or Apple/Command key under OS X is pressed. |
GetModifiers | Return the bit mask of all pressed modifier keys. |
HasModifiers | Returns True if any modifiers at all are pressed. |
MetaDown | Returns True if the Meta/Windows/Apple key is pressed. |
RawControlDown | Returns True if the Control key (also under OS X). |
SetAltDown | |
SetControlDown | |
SetMetaDown | |
SetRawControlDown | |
SetShiftDown | |
ShiftDown | Returns True if the Shift key is pressed. |
altDown | See AltDown and SetAltDown |
cmdDown | See CmdDown |
controlDown | See ControlDown and SetControlDown |
metaDown | See MetaDown and SetMetaDown |
shiftDown | See ShiftDown and SetShiftDown |
Provides methods for testing the state of the keyboard modifier keys.
Possible constructors:
KeyboardState(controlDown=False, shiftDown=False, altDown=False,
metaDown=False)
Constructor initializes the modifier key settings.
By default, no modifiers are active.
Parameters: |
|
---|
Returns True if the Alt key is pressed.
Notice that GetModifiers should usually be used instead of this one.
Return type: | bool |
---|
Returns True if the key used for command accelerators is pressed.
Same as ControlDown . Deprecated.
Notice that GetModifiers should usually be used instead of this one.
Return type: | bool |
---|
Returns True if the Control key or Apple/Command key under OS X is pressed.
This function doesn’t distinguish between right and left control keys.
Notice that GetModifiers should usually be used instead of this one.
Return type: | bool |
---|
Return the bit mask of all pressed modifier keys.
The return value is a combination of MOD_ALT , MOD_CONTROL , MOD_SHIFT and MOD_META bit masks. Additionally, MOD_NONE is defined as 0, i.e. corresponds to no modifiers (see HasModifiers ) and MOD_CMD is either MOD_CONTROL (MSW and Unix) or MOD_META (Mac), see CmdDown . See KeyModifier 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() and not AltDown() and not ShiftDown() and not MetaDown():
# handle Ctrl-XXX ...
HandleControl()
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() == wx.MOD_CONTROL:
# handle Ctrl-XXX ...
HandleControl()
with this function.
Return type: | int |
---|
Returns True if any modifiers at all are pressed.
This is equivalent to GetModifiers != MOD_NONE .
Return type: | bool |
---|
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 GetModifiers should usually be used instead of this one.
Return type: | bool |
---|
See also
Returns True if the Control key (also under OS X).
This function doesn’t distinguish between right and left control keys.
Notice that GetModifiers should usually be used instead of this one.
Return type: | bool |
---|
Parameters: | down (bool) – |
---|
Parameters: | down (bool) – |
---|
Parameters: | down (bool) – |
---|
Parameters: | down (bool) – |
---|
Parameters: | down (bool) – |
---|
Returns True if the Shift key is pressed.
This function doesn’t distinguish between right and left shift keys.
Notice that GetModifiers should usually be used instead of this one.
Return type: | bool |
---|
See AltDown and SetAltDown
See ControlDown and SetControlDown
See MetaDown and SetMetaDown
See ShiftDown and SetShiftDown