Mercurial > sdl-ios-xcode
annotate docs/html/sdlkeyboardevent.html @ 1212:7663bb0f52c7
To: sdl@libsdl.org
From: Christian Walther <cwalther@gmx.ch>
Date: Thu, 15 Dec 2005 21:19:53 +0100
Subject: [SDL] More mouse enhancements for Mac OS X
The attached patch brings two more enhancements to mouse handling on Mac
OS X (Quartz):
1. Currently, after launching an SDL application, SDL's notion of the
mouse position is stuck in the top left corner (0,0) until the first
time the mouse is moved. That's because the UpdateMouse() function isn't
implemented in the Quartz driver. This patch adds it.
2. When grabbing input while the mouse cursor is hidden, the function
CGAssociateMouseAndMouseCursorPosition(0) is called, which prevents the
system's notion of the mouse location from moving (and therefore leaving
the SDL window) even when the mouse is moved. However, apparently the
Wacom tablet driver (and maybe other special pointing device drivers)
doesn't care about that setting and still allows the mouse location to
go outside of the window. Interestingly, the system cursor, which is
made visible by the existing code in SDL in that case, does not follow
the mouse location, but appears in the middle of the SDL window. The
mouse location being outside of the window however means that mouse
button events go to background applications (or the dock or whatever is
there), which is very confusing to the user who sees no cursor outside
of the SDL window.
I have not found any way of intercepting these events (and that's
probably by design, as "normal" applications shouldn't prevent the user
from bringing other applications' windows to the front by clicking on
them). An idea would be placing a fully transparent, screen-filling
window in front of everything, but I fear that this might affect
rendering performance (by doing unnecessary compositing, using up
memory, or whatever).
The deluxe solution to the problem would be talking to the tablet
driver using AppleEvents to tell it to constrain its mapped area to the
window (see Wacom's "TabletEventDemo" sample app,
http://www.wacomeng.com/devsupport/mac/downloads.html), but I think that
the bloat that solution would add to SDL would outweigh its usefulness.
What I did instead in my patch is reassociating mouse and cursor when
the mouse leaves the window while an invisible grab is in effect, and
restoring the grab when the window is entered. That way, the grab can
still be effectively broken by a tablet, but at least it's obvious to
the user that it is broken. That change is minimal - it doesn't affect
operation with a mouse (or a trackpad), and the code that it adds is not
executed on every PumpEvents() call, only when entering and leaving the
window.
Unless there are any concerns about the patch, please apply. Feel free
to shorten the lengthy comment in SDL_QuartzEvents.m if you think it's
too verbose.
Thanks
-Christian
author | Ryan C. Gordon <icculus@icculus.org> |
---|---|
date | Mon, 02 Jan 2006 00:31:00 +0000 |
parents | 355632dca928 |
children |
rev | line source |
---|---|
0 | 1 <HTML |
2 ><HEAD | |
3 ><TITLE | |
4 >SDL_KeyboardEvent</TITLE | |
5 ><META | |
6 NAME="GENERATOR" | |
803
355632dca928
Updated SDL HTML documentation
Sam Lantinga <slouken@libsdl.org>
parents:
181
diff
changeset
|
7 CONTENT="Modular DocBook HTML Stylesheet Version 1.76b+ |
0 | 8 "><LINK |
9 REL="HOME" | |
10 TITLE="SDL Library Documentation" | |
11 HREF="index.html"><LINK | |
12 REL="UP" | |
13 TITLE="SDL Event Structures." | |
14 HREF="eventstructures.html"><LINK | |
15 REL="PREVIOUS" | |
16 TITLE="SDL_ActiveEvent" | |
17 HREF="sdlactiveevent.html"><LINK | |
18 REL="NEXT" | |
19 TITLE="SDL_MouseMotionEvent" | |
20 HREF="sdlmousemotionevent.html"></HEAD | |
21 ><BODY | |
22 CLASS="REFENTRY" | |
23 BGCOLOR="#FFF8DC" | |
24 TEXT="#000000" | |
25 LINK="#0000ee" | |
26 VLINK="#551a8b" | |
27 ALINK="#ff0000" | |
28 ><DIV | |
29 CLASS="NAVHEADER" | |
30 ><TABLE | |
803
355632dca928
Updated SDL HTML documentation
Sam Lantinga <slouken@libsdl.org>
parents:
181
diff
changeset
|
31 SUMMARY="Header navigation table" |
0 | 32 WIDTH="100%" |
33 BORDER="0" | |
34 CELLPADDING="0" | |
35 CELLSPACING="0" | |
36 ><TR | |
37 ><TH | |
38 COLSPAN="3" | |
39 ALIGN="center" | |
40 >SDL Library Documentation</TH | |
41 ></TR | |
42 ><TR | |
43 ><TD | |
44 WIDTH="10%" | |
45 ALIGN="left" | |
46 VALIGN="bottom" | |
47 ><A | |
48 HREF="sdlactiveevent.html" | |
803
355632dca928
Updated SDL HTML documentation
Sam Lantinga <slouken@libsdl.org>
parents:
181
diff
changeset
|
49 ACCESSKEY="P" |
0 | 50 >Prev</A |
51 ></TD | |
52 ><TD | |
53 WIDTH="80%" | |
54 ALIGN="center" | |
55 VALIGN="bottom" | |
56 ></TD | |
57 ><TD | |
58 WIDTH="10%" | |
59 ALIGN="right" | |
60 VALIGN="bottom" | |
61 ><A | |
62 HREF="sdlmousemotionevent.html" | |
803
355632dca928
Updated SDL HTML documentation
Sam Lantinga <slouken@libsdl.org>
parents:
181
diff
changeset
|
63 ACCESSKEY="N" |
0 | 64 >Next</A |
65 ></TD | |
66 ></TR | |
67 ></TABLE | |
68 ><HR | |
69 ALIGN="LEFT" | |
70 WIDTH="100%"></DIV | |
71 ><H1 | |
72 ><A | |
73 NAME="SDLKEYBOARDEVENT" | |
803
355632dca928
Updated SDL HTML documentation
Sam Lantinga <slouken@libsdl.org>
parents:
181
diff
changeset
|
74 ></A |
355632dca928
Updated SDL HTML documentation
Sam Lantinga <slouken@libsdl.org>
parents:
181
diff
changeset
|
75 >SDL_KeyboardEvent</H1 |
0 | 76 ><DIV |
77 CLASS="REFNAMEDIV" | |
78 ><A | |
803
355632dca928
Updated SDL HTML documentation
Sam Lantinga <slouken@libsdl.org>
parents:
181
diff
changeset
|
79 NAME="AEN4011" |
0 | 80 ></A |
81 ><H2 | |
82 >Name</H2 | |
83 >SDL_KeyboardEvent -- Keyboard event structure</DIV | |
84 ><DIV | |
85 CLASS="REFSECT1" | |
86 ><A | |
803
355632dca928
Updated SDL HTML documentation
Sam Lantinga <slouken@libsdl.org>
parents:
181
diff
changeset
|
87 NAME="AEN4014" |
0 | 88 ></A |
89 ><H2 | |
90 >Structure Definition</H2 | |
91 ><PRE | |
92 CLASS="PROGRAMLISTING" | |
93 >typedef struct{ | |
94 Uint8 type; | |
95 Uint8 state; | |
96 SDL_keysym keysym; | |
97 } SDL_KeyboardEvent;</PRE | |
98 ></DIV | |
99 ><DIV | |
100 CLASS="REFSECT1" | |
101 ><A | |
803
355632dca928
Updated SDL HTML documentation
Sam Lantinga <slouken@libsdl.org>
parents:
181
diff
changeset
|
102 NAME="AEN4017" |
0 | 103 ></A |
104 ><H2 | |
105 >Structure Data</H2 | |
106 ><DIV | |
107 CLASS="INFORMALTABLE" | |
108 ><A | |
803
355632dca928
Updated SDL HTML documentation
Sam Lantinga <slouken@libsdl.org>
parents:
181
diff
changeset
|
109 NAME="AEN4019" |
0 | 110 ></A |
111 ><P | |
112 ></P | |
113 ><TABLE | |
114 BORDER="0" | |
115 CLASS="CALSTABLE" | |
116 ><TBODY | |
117 ><TR | |
118 ><TD | |
119 ALIGN="LEFT" | |
120 VALIGN="TOP" | |
121 ><TT | |
122 CLASS="STRUCTFIELD" | |
123 ><I | |
124 >type</I | |
125 ></TT | |
126 ></TD | |
127 ><TD | |
128 ALIGN="LEFT" | |
129 VALIGN="TOP" | |
130 ><TT | |
131 CLASS="LITERAL" | |
132 >SDL_KEYDOWN</TT | |
133 > or <TT | |
134 CLASS="LITERAL" | |
135 >SDL_KEYUP</TT | |
136 ></TD | |
137 ></TR | |
138 ><TR | |
139 ><TD | |
140 ALIGN="LEFT" | |
141 VALIGN="TOP" | |
142 ><TT | |
143 CLASS="STRUCTFIELD" | |
144 ><I | |
145 >state</I | |
146 ></TT | |
147 ></TD | |
148 ><TD | |
149 ALIGN="LEFT" | |
150 VALIGN="TOP" | |
151 ><TT | |
152 CLASS="LITERAL" | |
153 >SDL_PRESSED</TT | |
154 > or <TT | |
155 CLASS="LITERAL" | |
156 >SDL_RELEASED</TT | |
157 ></TD | |
158 ></TR | |
159 ><TR | |
160 ><TD | |
161 ALIGN="LEFT" | |
162 VALIGN="TOP" | |
163 ><TT | |
164 CLASS="STRUCTFIELD" | |
165 ><I | |
166 >keysym</I | |
167 ></TT | |
168 ></TD | |
169 ><TD | |
170 ALIGN="LEFT" | |
171 VALIGN="TOP" | |
172 >Contains key press information</TD | |
173 ></TR | |
174 ></TBODY | |
175 ></TABLE | |
176 ><P | |
177 ></P | |
178 ></DIV | |
179 ></DIV | |
180 ><DIV | |
181 CLASS="REFSECT1" | |
182 ><A | |
803
355632dca928
Updated SDL HTML documentation
Sam Lantinga <slouken@libsdl.org>
parents:
181
diff
changeset
|
183 NAME="AEN4038" |
0 | 184 ></A |
185 ><H2 | |
186 >Description</H2 | |
187 ><P | |
188 ><SPAN | |
189 CLASS="STRUCTNAME" | |
190 >SDL_KeyboardEvent</SPAN | |
191 > is a member of the <A | |
192 HREF="sdlevent.html" | |
193 ><SPAN | |
194 CLASS="STRUCTNAME" | |
195 >SDL_Event</SPAN | |
196 ></A | |
197 > union and is used when an event of type <TT | |
198 CLASS="LITERAL" | |
199 >SDL_KEYDOWN</TT | |
200 > or <TT | |
201 CLASS="LITERAL" | |
202 >SDL_KEYUP</TT | |
203 > is reported.</P | |
204 ><P | |
205 >The <TT | |
206 CLASS="STRUCTFIELD" | |
207 ><I | |
208 >type</I | |
209 ></TT | |
210 > and <TT | |
211 CLASS="STRUCTFIELD" | |
212 ><I | |
213 >state</I | |
214 ></TT | |
215 > actually report the same information, they just use different values to do it! A keyboard event occurs when a key is released (<TT | |
216 CLASS="STRUCTFIELD" | |
217 ><I | |
218 >type</I | |
219 ></TT | |
220 >=<TT | |
221 CLASS="LITERAL" | |
222 >SDK_KEYUP</TT | |
223 > or <TT | |
224 CLASS="STRUCTFIELD" | |
225 ><I | |
226 >state</I | |
227 ></TT | |
228 >=<TT | |
229 CLASS="LITERAL" | |
230 >SDL_RELEASED</TT | |
231 >) and when a key is pressed (<TT | |
232 CLASS="STRUCTFIELD" | |
233 ><I | |
234 >type</I | |
235 ></TT | |
236 >=<TT | |
237 CLASS="LITERAL" | |
238 >SDL_KEYDOWN</TT | |
239 > or <TT | |
240 CLASS="STRUCTFIELD" | |
241 ><I | |
242 >state</I | |
243 ></TT | |
244 >=<TT | |
245 CLASS="LITERAL" | |
246 >SDL_PRESSED</TT | |
247 >). The information on what key was pressed or released is in the <A | |
248 HREF="sdlkeysym.html" | |
249 ><SPAN | |
250 CLASS="STRUCTNAME" | |
251 >keysym</SPAN | |
252 ></A | |
253 > structure.</P | |
254 ><DIV | |
255 CLASS="NOTE" | |
256 ><BLOCKQUOTE | |
257 CLASS="NOTE" | |
258 ><P | |
259 ><B | |
260 >Note: </B | |
261 >Repeating <TT | |
262 CLASS="LITERAL" | |
263 >SDL_KEYDOWN</TT | |
264 > events will occur if key repeat is enabled (see <A | |
265 HREF="sdlenablekeyrepeat.html" | |
266 ><TT | |
267 CLASS="FUNCTION" | |
268 >SDL_EnableKeyRepeat</TT | |
269 ></A | |
270 >).</P | |
271 ></BLOCKQUOTE | |
272 ></DIV | |
273 ></DIV | |
274 ><DIV | |
275 CLASS="REFSECT1" | |
276 ><A | |
803
355632dca928
Updated SDL HTML documentation
Sam Lantinga <slouken@libsdl.org>
parents:
181
diff
changeset
|
277 NAME="AEN4064" |
0 | 278 ></A |
279 ><H2 | |
280 >See Also</H2 | |
281 ><P | |
282 ><A | |
283 HREF="sdlevent.html" | |
284 ><SPAN | |
285 CLASS="STRUCTNAME" | |
286 >SDL_Event</SPAN | |
287 ></A | |
288 >, | |
289 <A | |
290 HREF="sdlkeysym.html" | |
291 ><SPAN | |
292 CLASS="STRUCTNAME" | |
293 >SDL_keysym</SPAN | |
294 ></A | |
295 >, | |
296 <A | |
297 HREF="sdlenablekeyrepeat.html" | |
298 ><TT | |
299 CLASS="FUNCTION" | |
300 >SDL_EnableKeyRepeat</TT | |
301 ></A | |
302 >, | |
303 <A | |
304 HREF="sdlenableunicode.html" | |
305 ><TT | |
306 CLASS="FUNCTION" | |
307 >SDL_EnableUNICODE</TT | |
308 ></A | |
309 ></P | |
310 ></DIV | |
311 ><DIV | |
312 CLASS="NAVFOOTER" | |
313 ><HR | |
314 ALIGN="LEFT" | |
315 WIDTH="100%"><TABLE | |
803
355632dca928
Updated SDL HTML documentation
Sam Lantinga <slouken@libsdl.org>
parents:
181
diff
changeset
|
316 SUMMARY="Footer navigation table" |
0 | 317 WIDTH="100%" |
318 BORDER="0" | |
319 CELLPADDING="0" | |
320 CELLSPACING="0" | |
321 ><TR | |
322 ><TD | |
323 WIDTH="33%" | |
324 ALIGN="left" | |
325 VALIGN="top" | |
326 ><A | |
327 HREF="sdlactiveevent.html" | |
803
355632dca928
Updated SDL HTML documentation
Sam Lantinga <slouken@libsdl.org>
parents:
181
diff
changeset
|
328 ACCESSKEY="P" |
0 | 329 >Prev</A |
330 ></TD | |
331 ><TD | |
332 WIDTH="34%" | |
333 ALIGN="center" | |
334 VALIGN="top" | |
335 ><A | |
336 HREF="index.html" | |
803
355632dca928
Updated SDL HTML documentation
Sam Lantinga <slouken@libsdl.org>
parents:
181
diff
changeset
|
337 ACCESSKEY="H" |
0 | 338 >Home</A |
339 ></TD | |
340 ><TD | |
341 WIDTH="33%" | |
342 ALIGN="right" | |
343 VALIGN="top" | |
344 ><A | |
345 HREF="sdlmousemotionevent.html" | |
803
355632dca928
Updated SDL HTML documentation
Sam Lantinga <slouken@libsdl.org>
parents:
181
diff
changeset
|
346 ACCESSKEY="N" |
0 | 347 >Next</A |
348 ></TD | |
349 ></TR | |
350 ><TR | |
351 ><TD | |
352 WIDTH="33%" | |
353 ALIGN="left" | |
354 VALIGN="top" | |
355 >SDL_ActiveEvent</TD | |
356 ><TD | |
357 WIDTH="34%" | |
358 ALIGN="center" | |
359 VALIGN="top" | |
360 ><A | |
361 HREF="eventstructures.html" | |
803
355632dca928
Updated SDL HTML documentation
Sam Lantinga <slouken@libsdl.org>
parents:
181
diff
changeset
|
362 ACCESSKEY="U" |
0 | 363 >Up</A |
364 ></TD | |
365 ><TD | |
366 WIDTH="33%" | |
367 ALIGN="right" | |
368 VALIGN="top" | |
369 >SDL_MouseMotionEvent</TD | |
370 ></TR | |
371 ></TABLE | |
372 ></DIV | |
373 ></BODY | |
374 ></HTML | |
375 > |