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