]>
Commit | Line | Data |
---|---|---|
a660d684 KB |
1 | \section{\class{wxKeyEvent}}\label{wxkeyevent} |
2 | ||
4ce81a75 | 3 | This event class contains information about keypress (character) events. |
a660d684 | 4 | |
fc2171bd | 5 | Notice that there are three different kinds of keyboard events in wxWidgets: |
f17393f1 VZ |
6 | key down and up events and char events. The difference between the first two |
7 | is clear - the first corresponds to a key press and the second to a key | |
8 | release - otherwise they are identical. Just note that if the key is | |
9 | maintained in a pressed state you will typically get a lot of (automatically | |
68304caf | 10 | generated) down events but only one up so it is wrong to assume that there is |
f17393f1 VZ |
11 | one up event corresponding to each down one. |
12 | ||
13 | Both key events provide untranslated key codes while the char event carries | |
14 | the translated one. The untranslated code for alphanumeric keys is always | |
15 | an upper case value. For the other keys it is one of {\tt WXK\_XXX} values | |
16 | from the \helpref{keycodes table}{keycodes}. The translated key is, in | |
17 | general, the character the user expects to appear as the result of the key | |
18 | combination when typing the text into a text entry zone, for example. | |
19 | ||
20 | A few examples to clarify this (all assume that {\sc Caps Lock} is unpressed | |
21 | and the standard US keyboard): when the {\tt 'A'} key is pressed, the key down | |
22 | event key code is equal to {\tt ASCII A} $== 65$. But the char event key code | |
23 | is {\tt ASCII a} $== 97$. On the other hand, if you press both {\sc Shift} and | |
24 | {\tt 'A'} keys simultaneously , the key code in key down event will still be | |
68304caf | 25 | just {\tt 'A'} while the char event key code parameter will now be {\tt 'A'} |
f17393f1 VZ |
26 | as well. |
27 | ||
28 | Although in this simple case it is clear that the correct key code could be | |
68304caf RD |
29 | found in the key down event handler by checking the value returned by |
30 | \helpref{ShiftDown()}{wxkeyeventshiftdown}, in general you should use | |
f17393f1 VZ |
31 | {\tt EVT\_CHAR} for this as for non alphanumeric keys the translation is |
32 | keyboard-layout dependent and can only be done properly by the system itself. | |
33 | ||
34 | Another kind of translation is done when the control key is pressed: for | |
35 | example, for {\sc Ctrl-A} key press the key down event still carries the | |
36 | same key code {\tt 'a'} as usual but the char event will have key code of | |
37 | $1$, the ASCII value of this key combination. | |
38 | ||
39 | You may discover how the other keys on your system behave interactively by | |
fc2171bd | 40 | running the \helpref{text}{sampletext} wxWidgets sample and pressing some keys |
f17393f1 VZ |
41 | in any of the text controls shown in it. |
42 | ||
af79fc6f RD |
43 | {\bf Note:} If a key down ({\tt EVT\_KEY\_DOWN}) event is caught and |
44 | the event handler does not call {\tt event.Skip()} then the coresponding | |
45 | char event ({\tt EVT\_CHAR}) will not happen. This is by design and | |
46 | enables the programs that handle both types of events to be a bit | |
47 | simpler. | |
48 | ||
fc2171bd | 49 | {\bf Note for Windows programmers:} The key and char events in wxWidgets are |
68304caf | 50 | similar to but slightly different from Windows {\tt WM\_KEYDOWN} and |
f17393f1 | 51 | {\tt WM\_CHAR} events. In particular, Alt-x combination will generate a char |
fc2171bd | 52 | event in wxWidgets (unless it is used as an accelerator). |
f17393f1 | 53 | |
f4fcc291 JS |
54 | {\bf Tip:} be sure to call {\tt event.Skip()} for events that you don't process in |
55 | key event function, otherwise menu shortcuts may cease to work under Windows. | |
56 | ||
a660d684 KB |
57 | \wxheading{Derived from} |
58 | ||
59 | \helpref{wxEvent}{wxevent} | |
60 | ||
954b8ae6 JS |
61 | \wxheading{Include files} |
62 | ||
63 | <wx/event.h> | |
64 | ||
a660d684 KB |
65 | \wxheading{Event table macros} |
66 | ||
67 | To process a key event, use these event handler macros to direct input to member | |
68 | functions that take a wxKeyEvent argument. | |
69 | ||
70 | \twocolwidtha{7cm} | |
71 | \begin{twocollist}\itemsep=0pt | |
4ce81a75 JS |
72 | \twocolitem{{\bf EVT\_KEY\_DOWN(func)}}{Process a wxEVT\_KEY\_DOWN event (any key has been pressed).} |
73 | \twocolitem{{\bf EVT\_KEY\_UP(func)}}{Process a wxEVT\_KEY\_UP event (any key has been released).} | |
a660d684 | 74 | \twocolitem{{\bf EVT\_CHAR(func)}}{Process a wxEVT\_CHAR event.} |
f17393f1 | 75 | %\twocolitem{{\bf EVT\_CHAR\_HOOK(func)}}{Process a wxEVT\_CHAR\_HOOK event.} |
a660d684 KB |
76 | \end{twocollist}% |
77 | ||
4ce81a75 | 78 | |
a660d684 KB |
79 | \latexignore{\rtfignore{\wxheading{Members}}} |
80 | ||
0d9b2c16 | 81 | |
f0e8a2d0 | 82 | \membersection{wxKeyEvent::m\_altDown}\label{wxkeyeventmaltdown} |
a660d684 KB |
83 | |
84 | \member{bool}{m\_altDown} | |
85 | ||
cc81d32f | 86 | true if the Alt key is pressed down. |
a660d684 | 87 | |
0d9b2c16 | 88 | |
f0e8a2d0 | 89 | \membersection{wxKeyEvent::m\_controlDown}\label{wxkeyeventmcontroldown} |
a660d684 KB |
90 | |
91 | \member{bool}{m\_controlDown} | |
92 | ||
cc81d32f | 93 | true if control is pressed down. |
a660d684 | 94 | |
0d9b2c16 | 95 | |
f0e8a2d0 | 96 | \membersection{wxKeyEvent::m\_keyCode}\label{wxkeyeventmkeycode} |
a660d684 KB |
97 | |
98 | \member{long}{m\_keyCode} | |
99 | ||
3972fb49 | 100 | Virtual keycode. See \helpref{Keycodes}{keycodes} for a list of identifiers. |
a660d684 | 101 | |
0d9b2c16 | 102 | |
f0e8a2d0 | 103 | \membersection{wxKeyEvent::m\_metaDown}\label{wxkeyeventmmetadown} |
a660d684 KB |
104 | |
105 | \member{bool}{m\_metaDown} | |
106 | ||
cc81d32f | 107 | true if the Meta key is pressed down. |
a660d684 | 108 | |
0d9b2c16 | 109 | |
f0e8a2d0 | 110 | \membersection{wxKeyEvent::m\_shiftDown}\label{wxkeyeventmshiftdown} |
a660d684 KB |
111 | |
112 | \member{bool}{m\_shiftDown} | |
113 | ||
cc81d32f | 114 | true if shift is pressed down. |
a660d684 | 115 | |
0d9b2c16 | 116 | |
f0e8a2d0 | 117 | \membersection{wxKeyEvent::m\_x}\label{wxkeyeventmx} |
a660d684 KB |
118 | |
119 | \member{int}{m\_x} | |
120 | ||
121 | X position of the event. | |
122 | ||
0d9b2c16 | 123 | |
f0e8a2d0 | 124 | \membersection{wxKeyEvent::m\_y}\label{wxkeyeventmy} |
a660d684 KB |
125 | |
126 | \member{int}{m\_y} | |
127 | ||
128 | Y position of the event. | |
129 | ||
0d9b2c16 | 130 | |
f0e8a2d0 | 131 | \membersection{wxKeyEvent::wxKeyEvent}\label{wxkeyeventctor} |
a660d684 KB |
132 | |
133 | \func{}{wxKeyEvent}{\param{WXTYPE}{ keyEventType}} | |
134 | ||
135 | Constructor. Currently, the only valid event types are wxEVT\_CHAR and wxEVT\_CHAR\_HOOK. | |
136 | ||
0d9b2c16 | 137 | |
f0e8a2d0 | 138 | \membersection{wxKeyEvent::AltDown}\label{wxkeyeventaltdown} |
a660d684 | 139 | |
803ef874 | 140 | \constfunc{bool}{AltDown}{\void} |
a660d684 | 141 | |
cc81d32f | 142 | Returns true if the Alt key was down at the time of the key event. |
a660d684 | 143 | |
0d9b2c16 | 144 | |
a2bd1520 VZ |
145 | \membersection{wxKeyEvent::CmdDown}\label{wxkeyeventcmddown} |
146 | ||
147 | \constfunc{bool}{CmdDown}{\void} | |
148 | ||
149 | "Cmd" is a pseudo key which is the same as Control for PC and Unix platforms | |
150 | but the special "Apple" (a.k.a as "Command") key under Macs: it makes often | |
151 | sense to use it instead of, say, ControlDown() because Cmd key is used for the | |
152 | same thing under Mac as Ctrl elsewhere (but Ctrl still exists, just not used | |
153 | for this purpose under Mac). So for non-Mac platforms this is the same as | |
154 | \helpref{ControlDown()}{wxkeyeventcontroldown} and under Mac this is the same | |
155 | as \helpref{MetaDown()}{wxkeyeventmetadown}. | |
156 | ||
157 | ||
158 | \membersection{wxKeyEvent::ControlDown}\label{wxkeyeventcontroldown} | |
a660d684 | 159 | |
803ef874 | 160 | \constfunc{bool}{ControlDown}{\void} |
a660d684 | 161 | |
cc81d32f | 162 | Returns true if the control key was down at the time of the key event. |
a660d684 | 163 | |
0d9b2c16 | 164 | |
f0e8a2d0 | 165 | \membersection{wxKeyEvent::GetKeyCode}\label{wxkeyeventgetkeycode} |
f6bcfd97 BP |
166 | |
167 | \constfunc{int}{GetKeyCode}{\void} | |
168 | ||
169 | Returns the virtual key code. ASCII events return normal ASCII values, | |
170 | while non-ASCII events return values such as {\bf WXK\_LEFT} for the | |
171 | left cursor key. See \helpref{Keycodes}{keycodes} for a full list of the virtual key codes. | |
172 | ||
0d9b2c16 | 173 | |
f0e8a2d0 | 174 | \membersection{wxKeyEvent::GetPosition}\label{wxkeyeventgetposition} |
0d9b2c16 VZ |
175 | |
176 | \constfunc{wxPoint}{GetPosition}{\void} | |
177 | ||
178 | \constfunc{void}{GetPosition}{\param{long *}{x}, \param{long *}{y}} | |
179 | ||
180 | Obtains the position (in client coordinates) at which the key was pressed. | |
181 | ||
182 | ||
f0e8a2d0 | 183 | \membersection{wxKeyEvent::GetRawKeyCode}\label{wxkeyeventgetrawkeycode} |
a160a325 VZ |
184 | |
185 | \constfunc{wxUint32}{GetRawKeyCode}{\void} | |
186 | ||
187 | Returns the raw key code for this event. This is a platform-dependent scan code | |
188 | which should only be used in advanced applications. | |
189 | ||
190 | {\bf NB:} Currently the raw key codes are not supported by all ports, use | |
7af3ca16 | 191 | {\tt\#ifdef wxHAS\_RAW\_KEY\_CODES} to determine if this feature is available. |
a160a325 | 192 | |
0d9b2c16 | 193 | |
f0e8a2d0 | 194 | \membersection{wxKeyEvent::GetRawKeyFlags}\label{wxkeyeventgetrawkeyflags} |
a160a325 VZ |
195 | |
196 | \constfunc{wxUint32}{GetRawKeyFlags}{\void} | |
197 | ||
198 | Returns the low level key flags for this event. The flags are | |
199 | platform-dependent and should only be used in advanced applications. | |
200 | ||
201 | {\bf NB:} Currently the raw key flags are not supported by all ports, use | |
7af3ca16 | 202 | {\tt \#ifdef wxHAS\_RAW\_KEY\_CODES} to determine if this feature is available. |
a160a325 | 203 | |
a660d684 | 204 | |
f0e8a2d0 | 205 | \membersection{wxKeyEvent::GetUnicodeKey}\label{wxkeyeventgetunicodekey} |
a660d684 | 206 | |
0d9b2c16 | 207 | \constfunc{wxChar}{GetUnicodeKey}{\void} |
a660d684 | 208 | |
0d9b2c16 | 209 | Returns the Unicode character corresponding to this key event. |
a660d684 | 210 | |
0d9b2c16 VZ |
211 | This function is only available in Unicode build, i.e. when |
212 | \texttt{wxUSE\_UNICODE} is $1$. | |
a660d684 | 213 | |
a660d684 | 214 | |
f0e8a2d0 | 215 | \membersection{wxKeyEvent::GetX}\label{wxkeyeventgetx} |
a660d684 | 216 | |
0d9b2c16 | 217 | \constfunc{long}{GetX}{\void} |
a660d684 | 218 | |
0d9b2c16 | 219 | Returns the X position (in client coordinates) of the event. |
a660d684 | 220 | |
a660d684 | 221 | |
f0e8a2d0 | 222 | \membersection{wxKeyEvent::GetY}\label{wxkeyeventgety} |
803ef874 | 223 | |
0d9b2c16 VZ |
224 | \constfunc{long}{GetY}{\void} |
225 | ||
226 | Returns the Y (in client coordinates) position of the event. | |
a660d684 | 227 | |
a660d684 | 228 | |
f0e8a2d0 | 229 | \membersection{wxKeyEvent::HasModifiers}\label{wxkeyeventhasmodifiers} |
f6bcfd97 BP |
230 | |
231 | \constfunc{bool}{HasModifiers}{\void} | |
232 | ||
cc81d32f | 233 | Returns true if either {\sc Ctrl} or {\sc Alt} keys was down |
f6bcfd97 | 234 | at the time of the key event. Note that this function does not take into |
d11710cb | 235 | account neither {\sc Shift} nor {\sc Meta} key states (the reason for ignoring |
68304caf | 236 | the latter is that it is common for {\sc NumLock} key to be configured as |
d11710cb VZ |
237 | {\sc Meta} under X but the key presses even while {\sc NumLock} is on should |
238 | be still processed normally). | |
f6bcfd97 | 239 | |
0d9b2c16 | 240 | |
a2bd1520 | 241 | \membersection{wxKeyEvent::MetaDown}\label{wxkeyeventmetadown} |
0d9b2c16 VZ |
242 | |
243 | \constfunc{bool}{MetaDown}{\void} | |
244 | ||
245 | Returns true if the Meta key was down at the time of the key event. | |
246 | ||
247 | ||
f17393f1 | 248 | \membersection{wxKeyEvent::ShiftDown}\label{wxkeyeventshiftdown} |
a660d684 | 249 | |
803ef874 | 250 | \constfunc{bool}{ShiftDown}{\void} |
a660d684 | 251 | |
cc81d32f | 252 | Returns true if the shift key was down at the time of the key event. |
a660d684 | 253 |