File: kbdstate.h

package info (click to toggle)
wxwidgets3.0 3.0.5.1%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 120,464 kB
  • sloc: cpp: 896,633; makefile: 52,303; ansic: 21,971; sh: 5,713; python: 2,940; xml: 1,534; perl: 264; javascript: 33
file content (160 lines) | stat: -rw-r--r-- 5,231 bytes parent folder | download | duplicates (10)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
/////////////////////////////////////////////////////////////////////////////
// Name:        wx/kbdstate.h
// Purpose:     documentation of wxKeyboardState
// Author:      wxWidgets team
// Created:     2008-09-19
// Licence:     wxWindows licence
/////////////////////////////////////////////////////////////////////////////

/**
    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.

    This class is implemented entirely inline in @<wx/kbdstate.h@> and thus has
    no linking requirements.

    @nolibrary
    @category{events}

    @see wxKeyEvent, wxMouseState
 */
class wxKeyboardState
{
public:
    /**
        Constructor initializes the modifier key settings.

        By default, no modifiers are active.
     */
    wxKeyboardState(bool controlDown = false,
                    bool shiftDown = false,
                    bool altDown = false,
                    bool metaDown = false);

    /**
        Return the bit mask of all pressed modifier keys.

        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
        is defined as 0, i.e. corresponds to no modifiers (see HasAnyModifiers())
        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.

        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.

        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.
     */
    bool HasModifiers() const;

    /**
        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.
     */
    bool ControlDown() const;

    /**
        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.
     */
    bool RawControlDown() const;

    /**
        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
        under Unix systems, Windows keys under MSW 
        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;

    /**
        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.
     */
    bool CmdDown() const;

    
    void SetControlDown(bool down);
    void SetRawControlDown(bool down);
    void SetShiftDown(bool down);
    void SetAltDown(bool down);
    void SetMetaDown(bool down);

};