]> git.saurik.com Git - wxWidgets.git/blame - docs/latex/wx/keyevent.tex
Added missing brace in checkbox.tex
[wxWidgets.git] / docs / latex / wx / keyevent.tex
CommitLineData
a660d684
KB
1\section{\class{wxKeyEvent}}\label{wxkeyevent}
2
4ce81a75 3This event class contains information about keypress (character) events.
a660d684 4
f17393f1
VZ
5Notice that there are three different kinds of keyboard events in wxWindows:
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
68304caf 10generated) down events but only one up so it is wrong to assume that there is
f17393f1
VZ
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
68304caf
RD
20If the key up event is caught and the event handler does not call
21event.Skip() then the coresponding char event will not happen. This
22is by design and enables the programs that handle both types of events
23to be a bit simpler.
24
f17393f1
VZ
25A few examples to clarify this (all assume that {\sc Caps Lock} is unpressed
26and the standard US keyboard): when the {\tt 'A'} key is pressed, the key down
27event key code is equal to {\tt ASCII A} $== 65$. But the char event key code
28is {\tt ASCII a} $== 97$. On the other hand, if you press both {\sc Shift} and
29{\tt 'A'} keys simultaneously , the key code in key down event will still be
68304caf 30just {\tt 'A'} while the char event key code parameter will now be {\tt 'A'}
f17393f1
VZ
31as well.
32
33Although in this simple case it is clear that the correct key code could be
68304caf
RD
34found in the key down event handler by checking the value returned by
35\helpref{ShiftDown()}{wxkeyeventshiftdown}, in general you should use
f17393f1
VZ
36{\tt EVT\_CHAR} for this as for non alphanumeric keys the translation is
37keyboard-layout dependent and can only be done properly by the system itself.
38
39Another kind of translation is done when the control key is pressed: for
40example, for {\sc Ctrl-A} key press the key down event still carries the
41same key code {\tt 'a'} as usual but the char event will have key code of
42$1$, the ASCII value of this key combination.
43
44You may discover how the other keys on your system behave interactively by
45running the \helpref{text}{sampletext} wxWindows sample and pressing some keys
46in any of the text controls shown in it.
47
48{\bf Note for Windows programmers:} The key and char events in wxWindows are
68304caf 49similar to but slightly different from Windows {\tt WM\_KEYDOWN} and
f17393f1
VZ
50{\tt WM\_CHAR} events. In particular, Alt-x combination will generate a char
51event in wxWindows (unless it is used as an acclerator).
52
f4fcc291
JS
53{\bf Tip:} be sure to call {\tt event.Skip()} for events that you don't process in
54key event function, otherwise menu shortcuts may cease to work under Windows.
55
a660d684
KB
56\wxheading{Derived from}
57
58\helpref{wxEvent}{wxevent}
59
954b8ae6
JS
60\wxheading{Include files}
61
62<wx/event.h>
63
a660d684
KB
64\wxheading{Event table macros}
65
66To process a key event, use these event handler macros to direct input to member
67functions that take a wxKeyEvent argument.
68
69\twocolwidtha{7cm}
70\begin{twocollist}\itemsep=0pt
4ce81a75
JS
71\twocolitem{{\bf EVT\_KEY\_DOWN(func)}}{Process a wxEVT\_KEY\_DOWN event (any key has been pressed).}
72\twocolitem{{\bf EVT\_KEY\_UP(func)}}{Process a wxEVT\_KEY\_UP event (any key has been released).}
a660d684 73\twocolitem{{\bf EVT\_CHAR(func)}}{Process a wxEVT\_CHAR event.}
f17393f1 74%\twocolitem{{\bf EVT\_CHAR\_HOOK(func)}}{Process a wxEVT\_CHAR\_HOOK event.}
a660d684
KB
75\end{twocollist}%
76
4ce81a75 77
a660d684
KB
78\latexignore{\rtfignore{\wxheading{Members}}}
79
80\membersection{wxKeyEvent::m\_altDown}
81
82\member{bool}{m\_altDown}
83
84TRUE if the Alt key is pressed down.
85
86\membersection{wxKeyEvent::m\_controlDown}
87
88\member{bool}{m\_controlDown}
89
90TRUE if control is pressed down.
91
92\membersection{wxKeyEvent::m\_keyCode}
93
94\member{long}{m\_keyCode}
95
3972fb49 96Virtual keycode. See \helpref{Keycodes}{keycodes} for a list of identifiers.
a660d684
KB
97
98\membersection{wxKeyEvent::m\_metaDown}
99
100\member{bool}{m\_metaDown}
101
102TRUE if the Meta key is pressed down.
103
104\membersection{wxKeyEvent::m\_shiftDown}
105
106\member{bool}{m\_shiftDown}
107
108TRUE if shift is pressed down.
109
110\membersection{wxKeyEvent::m\_x}
111
112\member{int}{m\_x}
113
114X position of the event.
115
116\membersection{wxKeyEvent::m\_y}
117
118\member{int}{m\_y}
119
120Y position of the event.
121
122\membersection{wxKeyEvent::wxKeyEvent}
123
124\func{}{wxKeyEvent}{\param{WXTYPE}{ keyEventType}}
125
126Constructor. Currently, the only valid event types are wxEVT\_CHAR and wxEVT\_CHAR\_HOOK.
127
128\membersection{wxKeyEvent::AltDown}
129
803ef874 130\constfunc{bool}{AltDown}{\void}
a660d684
KB
131
132Returns TRUE if the Alt key was down at the time of the key event.
133
134\membersection{wxKeyEvent::ControlDown}
135
803ef874 136\constfunc{bool}{ControlDown}{\void}
a660d684
KB
137
138Returns TRUE if the control key was down at the time of the key event.
139
f6bcfd97
BP
140\membersection{wxKeyEvent::GetKeyCode}
141
142\constfunc{int}{GetKeyCode}{\void}
143
144Returns the virtual key code. ASCII events return normal ASCII values,
145while non-ASCII events return values such as {\bf WXK\_LEFT} for the
146left cursor key. See \helpref{Keycodes}{keycodes} for a full list of the virtual key codes.
147
a160a325
VZ
148\membersection{wxKeyEvent::GetRawKeyCode}
149
150\constfunc{wxUint32}{GetRawKeyCode}{\void}
151
152Returns the raw key code for this event. This is a platform-dependent scan code
153which should only be used in advanced applications.
154
155{\bf NB:} Currently the raw key codes are not supported by all ports, use
7af3ca16 156{\tt\#ifdef wxHAS\_RAW\_KEY\_CODES} to determine if this feature is available.
a160a325
VZ
157
158\membersection{wxKeyEvent::GetRawKeyFlags}
159
160\constfunc{wxUint32}{GetRawKeyFlags}{\void}
161
162Returns the low level key flags for this event. The flags are
163platform-dependent and should only be used in advanced applications.
164
165{\bf NB:} Currently the raw key flags are not supported by all ports, use
7af3ca16 166{\tt \#ifdef wxHAS\_RAW\_KEY\_CODES} to determine if this feature is available.
a160a325 167
a660d684
KB
168\membersection{wxKeyEvent::GetX}
169
803ef874 170\constfunc{long}{GetX}{\void}
a660d684
KB
171
172Returns the X position of the event.
173
174\membersection{wxKeyEvent::GetY}
175
803ef874 176\constfunc{long}{GetY}{\void}
a660d684
KB
177
178Returns the Y position of the event.
179
a660d684
KB
180\membersection{wxKeyEvent::MetaDown}
181
803ef874 182\constfunc{bool}{MetaDown}{\void}
a660d684
KB
183
184Returns TRUE if the Meta key was down at the time of the key event.
185
803ef874 186\membersection{wxKeyEvent::GetPosition}
a660d684 187
803ef874
JS
188\constfunc{wxPoint}{GetPosition}{\void}
189
190\constfunc{void}{GetPosition}{\param{long *}{x}, \param{long *}{y}}
a660d684
KB
191
192Obtains the position at which the key was pressed.
193
f6bcfd97
BP
194\membersection{wxKeyEvent::HasModifiers}
195
196\constfunc{bool}{HasModifiers}{\void}
197
d11710cb 198Returns TRUE if either {\sc Ctrl} or {\sc Alt} keys was down
f6bcfd97 199at the time of the key event. Note that this function does not take into
d11710cb 200account neither {\sc Shift} nor {\sc Meta} key states (the reason for ignoring
68304caf 201the latter is that it is common for {\sc NumLock} key to be configured as
d11710cb
VZ
202{\sc Meta} under X but the key presses even while {\sc NumLock} is on should
203be still processed normally).
f6bcfd97 204
f17393f1 205\membersection{wxKeyEvent::ShiftDown}\label{wxkeyeventshiftdown}
a660d684 206
803ef874 207\constfunc{bool}{ShiftDown}{\void}
a660d684
KB
208
209Returns TRUE if the shift key was down at the time of the key event.
210