1 ///////////////////////////////////////////////////////////////////////////////
3 // Purpose: Declaration of wxKeyboardState class
4 // Author: Vadim Zeitlin
6 // Copyright: (c) 2008 Vadim Zeitlin <vadim@wxwidgets.org>
7 // Licence: wxWindows licence
8 ///////////////////////////////////////////////////////////////////////////////
10 #ifndef _WX_KBDSTATE_H_
11 #define _WX_KBDSTATE_H_
15 // ----------------------------------------------------------------------------
16 // wxKeyboardState stores the state of the keyboard modifier keys
17 // ----------------------------------------------------------------------------
19 class WXDLLIMPEXP_CORE wxKeyboardState
22 wxKeyboardState(bool controlDown
= false,
23 bool shiftDown
= false,
25 bool metaDown
= false)
26 : m_controlDown(controlDown
),
27 m_shiftDown(shiftDown
),
31 ,m_rawControlDown(false)
36 // default copy ctor, assignment operator and dtor are ok
39 // accessors for the various modifier keys
40 // ---------------------------------------
42 // should be used check if the key event has exactly the given modifiers:
43 // "GetModifiers() = wxMOD_CONTROL" is easier to write than "ControlDown()
44 // && !MetaDown() && !AltDown() && !ShiftDown()"
45 int GetModifiers() const
47 return (m_controlDown
? wxMOD_CONTROL
: 0) |
48 (m_shiftDown
? wxMOD_SHIFT
: 0) |
49 (m_metaDown
? wxMOD_META
: 0) |
51 (m_rawControlDown
? wxMOD_RAW_CONTROL
: 0) |
53 (m_altDown
? wxMOD_ALT
: 0);
56 // returns true if any modifiers at all are pressed
57 bool HasAnyModifiers() const { return GetModifiers() != wxMOD_NONE
; }
59 // returns true if any modifiers changing the usual key interpretation are
60 // pressed, notably excluding Shift
61 bool HasModifiers() const
63 return ControlDown() || RawControlDown() || AltDown();
66 // accessors for individual modifier keys
67 bool ControlDown() const { return m_controlDown
; }
68 bool RawControlDown() const
71 return m_rawControlDown
;
76 bool ShiftDown() const { return m_shiftDown
; }
77 bool MetaDown() const { return m_metaDown
; }
78 bool AltDown() const { return m_altDown
; }
80 // "Cmd" is a pseudo key which is Control for PC and Unix platforms but
81 // Apple ("Command") key under Macs: it makes often sense to use it instead
82 // of, say, ControlDown() because Cmd key is used for the same thing under
83 // Mac as Ctrl elsewhere (but Ctrl still exists, just not used for this
90 // these functions are mostly used by wxWidgets itself
91 // ---------------------------------------------------
93 void SetControlDown(bool down
) { m_controlDown
= down
; }
94 void SetRawControlDown(bool down
)
97 m_rawControlDown
= down
;
102 void SetShiftDown(bool down
) { m_shiftDown
= down
; }
103 void SetAltDown(bool down
) { m_altDown
= down
; }
104 void SetMetaDown(bool down
) { m_metaDown
= down
; }
107 // for backwards compatibility with the existing code accessing these
108 // members of wxKeyEvent directly, these variables are public, however you
109 // should not use them in any new code, please use the accessors instead
111 bool m_controlDown
: 1;
112 bool m_shiftDown
: 1;
116 bool m_rawControlDown
: 1;
120 #endif // _WX_KBDSTATE_H_