2008-09-19 14:41:41 -04:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: wx/kbdstate.h
|
|
|
|
// Purpose: documentation of wxKeyboardState
|
|
|
|
// Author: wxWidgets team
|
|
|
|
// Created: 2008-09-19
|
2010-07-13 09:29:13 -04:00
|
|
|
// Licence: wxWindows licence
|
2008-09-19 14:41:41 -04:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
/**
|
|
|
|
Provides methods for testing the state of the keyboard modifier keys.
|
|
|
|
|
|
|
|
This class is used as a base class of wxKeyEvent and wxMouseState and,
|
|
|
|
hence, indirectly, of wxMouseEvent, so its methods may be used to get
|
|
|
|
information about the modifier keys which were pressed when the event
|
|
|
|
occurred.
|
|
|
|
|
2009-01-27 19:51:55 -05:00
|
|
|
This class is implemented entirely inline in @<wx/kbdstate.h@> and thus has
|
2008-09-19 14:41:41 -04:00
|
|
|
no linking requirements.
|
|
|
|
|
2009-01-27 19:51:55 -05:00
|
|
|
@nolibrary
|
2009-05-01 18:37:14 -04:00
|
|
|
@category{events}
|
2008-09-19 14:41:41 -04:00
|
|
|
|
|
|
|
@see wxKeyEvent, wxMouseState
|
|
|
|
*/
|
|
|
|
class wxKeyboardState
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
2008-09-19 19:59:39 -04:00
|
|
|
Constructor initializes the modifier key settings.
|
2008-09-19 14:41:41 -04:00
|
|
|
|
|
|
|
By default, no modifiers are active.
|
|
|
|
*/
|
2008-11-10 16:33:25 -05:00
|
|
|
wxKeyboardState(bool controlDown = false,
|
|
|
|
bool shiftDown = false,
|
|
|
|
bool altDown = false,
|
|
|
|
bool metaDown = false);
|
2008-09-19 14:41:41 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
Return the bit mask of all pressed modifier keys.
|
2008-11-10 16:33:25 -05:00
|
|
|
|
2008-09-19 14:41:41 -04:00
|
|
|
The return value is a combination of @c wxMOD_ALT, @c wxMOD_CONTROL,
|
|
|
|
@c wxMOD_SHIFT and @c wxMOD_META bit masks. Additionally, @c wxMOD_NONE
|
2012-07-29 18:08:09 -04:00
|
|
|
is defined as 0, i.e. corresponds to no modifiers (see HasAnyModifiers())
|
2009-01-27 19:51:55 -05:00
|
|
|
and @c wxMOD_CMD is either @c wxMOD_CONTROL (MSW and Unix) or
|
|
|
|
@c wxMOD_META (Mac), see CmdDown().
|
|
|
|
See ::wxKeyModifier for the full list of modifiers.
|
2008-09-19 14:41:41 -04:00
|
|
|
|
|
|
|
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:
|
|
|
|
|
|
|
|
@code
|
|
|
|
if ( ControlDown() && !AltDown() && !ShiftDown() && !MetaDown() )
|
|
|
|
... handle Ctrl-XXX ...
|
|
|
|
@endcode
|
|
|
|
|
|
|
|
and forgetting to do it can result in serious program bugs (e.g. program
|
|
|
|
not working with European keyboard layout where @c AltGr key which is
|
|
|
|
seen by the program as combination of CTRL and ALT is used). On the
|
|
|
|
other hand, you can simply write:
|
|
|
|
|
|
|
|
@code
|
|
|
|
if ( GetModifiers() == wxMOD_CONTROL )
|
|
|
|
... handle Ctrl-XXX ...
|
|
|
|
@endcode
|
|
|
|
|
|
|
|
with this function.
|
|
|
|
*/
|
|
|
|
int GetModifiers() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
Returns true if any modifiers at all are pressed.
|
|
|
|
|
|
|
|
This is equivalent to @c GetModifiers() @c != @c wxMOD_NONE.
|
2012-07-29 18:08:09 -04:00
|
|
|
|
|
|
|
Notice that this is different from HasModifiers() method which doesn't
|
|
|
|
take e.g. Shift modifier into account. This method is most suitable for
|
|
|
|
mouse events when any modifier, including Shift, can change the
|
|
|
|
interpretation of the event.
|
|
|
|
|
|
|
|
@since 2.9.5
|
|
|
|
*/
|
|
|
|
bool HasAnyModifiers() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
Returns true if Control or Alt are pressed.
|
|
|
|
|
|
|
|
Checks if Control, Alt or, under OS X 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 HasAnyModifiers() if you want to
|
|
|
|
take Shift into account as well.
|
2008-09-19 14:41:41 -04:00
|
|
|
*/
|
|
|
|
bool HasModifiers() const;
|
|
|
|
|
|
|
|
/**
|
2011-08-23 09:03:52 -04:00
|
|
|
Returns true if the Control key or Apple/Command key under OS X is pressed.
|
2008-09-19 14:41:41 -04:00
|
|
|
|
|
|
|
This function doesn't distinguish between right and left control keys.
|
|
|
|
|
|
|
|
Notice that GetModifiers() should usually be used instead of this one.
|
|
|
|
*/
|
|
|
|
bool ControlDown() const;
|
|
|
|
|
2011-08-23 09:03:52 -04:00
|
|
|
/**
|
|
|
|
Returns true if the Control key (also under OS X).
|
2019-01-30 11:28:08 -05:00
|
|
|
|
2011-08-23 09:03:52 -04:00
|
|
|
This function doesn't distinguish between right and left control keys.
|
2019-01-30 11:28:08 -05:00
|
|
|
|
2011-08-23 09:03:52 -04:00
|
|
|
Notice that GetModifiers() should usually be used instead of this one.
|
|
|
|
*/
|
|
|
|
bool RawControlDown() const;
|
|
|
|
|
2008-09-19 14:41:41 -04:00
|
|
|
/**
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
bool ShiftDown() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
Returns true if the Meta/Windows/Apple key is pressed.
|
|
|
|
|
|
|
|
This function tests the state of the key traditionally called Meta
|
2019-01-30 11:28:08 -05:00
|
|
|
under Unix systems, Windows keys under MSW
|
2008-09-19 14:41:41 -04:00
|
|
|
Notice that GetModifiers() should usually be used instead of this one.
|
|
|
|
|
|
|
|
@see CmdDown()
|
|
|
|
*/
|
|
|
|
bool MetaDown() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
Returns true if the Alt key is pressed.
|
|
|
|
|
|
|
|
Notice that GetModifiers() should usually be used instead of this one.
|
|
|
|
*/
|
|
|
|
bool AltDown() const;
|
|
|
|
|
|
|
|
/**
|
2011-08-23 09:03:52 -04:00
|
|
|
Returns true if the key used for command accelerators is pressed. Same as
|
|
|
|
ControlDown(). Deprecated.
|
2008-09-19 14:41:41 -04:00
|
|
|
|
|
|
|
Notice that GetModifiers() should usually be used instead of this one.
|
|
|
|
*/
|
|
|
|
bool CmdDown() const;
|
2010-11-19 02:57:19 -05:00
|
|
|
|
2019-01-30 11:28:08 -05:00
|
|
|
|
2010-11-19 02:57:19 -05:00
|
|
|
void SetControlDown(bool down);
|
2011-08-23 09:03:52 -04:00
|
|
|
void SetRawControlDown(bool down);
|
2010-11-19 02:57:19 -05:00
|
|
|
void SetShiftDown(bool down);
|
|
|
|
void SetAltDown(bool down);
|
|
|
|
void SetMetaDown(bool down);
|
|
|
|
|
2008-09-19 14:41:41 -04:00
|
|
|
};
|
|
|
|
|