]> git.saurik.com Git - wxWidgets.git/blame - docs/latex/wx/keyevent.tex
a temporary hack to make testing wxTLW/Univ easier
[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
10generated) down events but only up one 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} wxWindows sample and pressing some keys
41in any of the text controls shown in it.
42
43{\bf Note for Windows programmers:} The key and char events in wxWindows are
44similar to but slightly different from Windows {\tt WM\_KEYDOWN} and
45{\tt WM\_CHAR} events. In particular, Alt-x combination will generate a char
46event in wxWindows (unless it is used as an acclerator).
47
a660d684
KB
48\wxheading{Derived from}
49
50\helpref{wxEvent}{wxevent}
51
954b8ae6
JS
52\wxheading{Include files}
53
54<wx/event.h>
55
a660d684
KB
56\wxheading{Event table macros}
57
58To process a key event, use these event handler macros to direct input to member
59functions that take a wxKeyEvent argument.
60
61\twocolwidtha{7cm}
62\begin{twocollist}\itemsep=0pt
4ce81a75
JS
63\twocolitem{{\bf EVT\_KEY\_DOWN(func)}}{Process a wxEVT\_KEY\_DOWN event (any key has been pressed).}
64\twocolitem{{\bf EVT\_KEY\_UP(func)}}{Process a wxEVT\_KEY\_UP event (any key has been released).}
a660d684 65\twocolitem{{\bf EVT\_CHAR(func)}}{Process a wxEVT\_CHAR event.}
f17393f1 66%\twocolitem{{\bf EVT\_CHAR\_HOOK(func)}}{Process a wxEVT\_CHAR\_HOOK event.}
a660d684
KB
67\end{twocollist}%
68
4ce81a75
JS
69\wxheading{See also}
70
71\helpref{wxWindow::OnChar}{wxwindowonchar},
72\helpref{wxWindow::OnCharHook}{wxwindowoncharhook},
73\helpref{wxWindow::OnKeyDown}{wxwindowonkeydown},
74\helpref{wxWindow::OnKeyUp}{wxwindowonkeyup}
75
a660d684
KB
76\latexignore{\rtfignore{\wxheading{Members}}}
77
78\membersection{wxKeyEvent::m\_altDown}
79
80\member{bool}{m\_altDown}
81
82TRUE if the Alt key is pressed down.
83
84\membersection{wxKeyEvent::m\_controlDown}
85
86\member{bool}{m\_controlDown}
87
88TRUE if control is pressed down.
89
90\membersection{wxKeyEvent::m\_keyCode}
91
92\member{long}{m\_keyCode}
93
3972fb49 94Virtual keycode. See \helpref{Keycodes}{keycodes} for a list of identifiers.
a660d684
KB
95
96\membersection{wxKeyEvent::m\_metaDown}
97
98\member{bool}{m\_metaDown}
99
100TRUE if the Meta key is pressed down.
101
102\membersection{wxKeyEvent::m\_shiftDown}
103
104\member{bool}{m\_shiftDown}
105
106TRUE if shift is pressed down.
107
108\membersection{wxKeyEvent::m\_x}
109
110\member{int}{m\_x}
111
112X position of the event.
113
114\membersection{wxKeyEvent::m\_y}
115
116\member{int}{m\_y}
117
118Y position of the event.
119
120\membersection{wxKeyEvent::wxKeyEvent}
121
122\func{}{wxKeyEvent}{\param{WXTYPE}{ keyEventType}}
123
124Constructor. Currently, the only valid event types are wxEVT\_CHAR and wxEVT\_CHAR\_HOOK.
125
126\membersection{wxKeyEvent::AltDown}
127
803ef874 128\constfunc{bool}{AltDown}{\void}
a660d684
KB
129
130Returns TRUE if the Alt key was down at the time of the key event.
131
132\membersection{wxKeyEvent::ControlDown}
133
803ef874 134\constfunc{bool}{ControlDown}{\void}
a660d684
KB
135
136Returns TRUE if the control key was down at the time of the key event.
137
f6bcfd97
BP
138\membersection{wxKeyEvent::GetKeyCode}
139
140\constfunc{int}{GetKeyCode}{\void}
141
142Returns the virtual key code. ASCII events return normal ASCII values,
143while non-ASCII events return values such as {\bf WXK\_LEFT} for the
144left cursor key. See \helpref{Keycodes}{keycodes} for a full list of the virtual key codes.
145
a660d684
KB
146\membersection{wxKeyEvent::GetX}
147
803ef874 148\constfunc{long}{GetX}{\void}
a660d684
KB
149
150Returns the X position of the event.
151
152\membersection{wxKeyEvent::GetY}
153
803ef874 154\constfunc{long}{GetY}{\void}
a660d684
KB
155
156Returns the Y position of the event.
157
a660d684
KB
158\membersection{wxKeyEvent::MetaDown}
159
803ef874 160\constfunc{bool}{MetaDown}{\void}
a660d684
KB
161
162Returns TRUE if the Meta key was down at the time of the key event.
163
803ef874 164\membersection{wxKeyEvent::GetPosition}
a660d684 165
803ef874
JS
166\constfunc{wxPoint}{GetPosition}{\void}
167
168\constfunc{void}{GetPosition}{\param{long *}{x}, \param{long *}{y}}
a660d684
KB
169
170Obtains the position at which the key was pressed.
171
f6bcfd97
BP
172\membersection{wxKeyEvent::HasModifiers}
173
174\constfunc{bool}{HasModifiers}{\void}
175
d11710cb 176Returns TRUE if either {\sc Ctrl} or {\sc Alt} keys was down
f6bcfd97 177at the time of the key event. Note that this function does not take into
d11710cb
VZ
178account neither {\sc Shift} nor {\sc Meta} key states (the reason for ignoring
179the latter is that it is common for {\sc NumLock} key to be configured as
180{\sc Meta} under X but the key presses even while {\sc NumLock} is on should
181be still processed normally).
f6bcfd97 182
f17393f1 183\membersection{wxKeyEvent::ShiftDown}\label{wxkeyeventshiftdown}
a660d684 184
803ef874 185\constfunc{bool}{ShiftDown}{\void}
a660d684
KB
186
187Returns TRUE if the shift key was down at the time of the key event.
188
189