comparison docs/html/guideinputkeyboard.html @ 803:355632dca928

Updated SDL HTML documentation
author Sam Lantinga <slouken@libsdl.org>
date Tue, 10 Feb 2004 15:15:40 +0000
parents 55f1f1b3e27d
children
comparison
equal deleted inserted replaced
802:3c609d54f100 803:355632dca928
2 ><HEAD 2 ><HEAD
3 ><TITLE 3 ><TITLE
4 >Handling the Keyboard</TITLE 4 >Handling the Keyboard</TITLE
5 ><META 5 ><META
6 NAME="GENERATOR" 6 NAME="GENERATOR"
7 CONTENT="Modular DocBook HTML Stylesheet Version 1.64 7 CONTENT="Modular DocBook HTML Stylesheet Version 1.76b+
8 "><LINK 8 "><LINK
9 REL="HOME" 9 REL="HOME"
10 TITLE="SDL Library Documentation" 10 TITLE="SDL Library Documentation"
11 HREF="index.html"><LINK 11 HREF="index.html"><LINK
12 REL="UP" 12 REL="UP"
26 VLINK="#551a8b" 26 VLINK="#551a8b"
27 ALINK="#ff0000" 27 ALINK="#ff0000"
28 ><DIV 28 ><DIV
29 CLASS="NAVHEADER" 29 CLASS="NAVHEADER"
30 ><TABLE 30 ><TABLE
31 SUMMARY="Header navigation table"
31 WIDTH="100%" 32 WIDTH="100%"
32 BORDER="0" 33 BORDER="0"
33 CELLPADDING="0" 34 CELLPADDING="0"
34 CELLSPACING="0" 35 CELLSPACING="0"
35 ><TR 36 ><TR
43 WIDTH="10%" 44 WIDTH="10%"
44 ALIGN="left" 45 ALIGN="left"
45 VALIGN="bottom" 46 VALIGN="bottom"
46 ><A 47 ><A
47 HREF="guideinput.html" 48 HREF="guideinput.html"
49 ACCESSKEY="P"
48 >Prev</A 50 >Prev</A
49 ></TD 51 ></TD
50 ><TD 52 ><TD
51 WIDTH="80%" 53 WIDTH="80%"
52 ALIGN="center" 54 ALIGN="center"
56 WIDTH="10%" 58 WIDTH="10%"
57 ALIGN="right" 59 ALIGN="right"
58 VALIGN="bottom" 60 VALIGN="bottom"
59 ><A 61 ><A
60 HREF="guideexamples.html" 62 HREF="guideexamples.html"
63 ACCESSKEY="N"
61 >Next</A 64 >Next</A
62 ></TD 65 ></TD
63 ></TR 66 ></TR
64 ></TABLE 67 ></TABLE
65 ><HR 68 ><HR
69 CLASS="SECT1" 72 CLASS="SECT1"
70 ><H1 73 ><H1
71 CLASS="SECT1" 74 CLASS="SECT1"
72 ><A 75 ><A
73 NAME="GUIDEINPUTKEYBOARD" 76 NAME="GUIDEINPUTKEYBOARD"
74 >Handling the Keyboard</A 77 ></A
75 ></H1 78 >Handling the Keyboard</H1
76 ><DIV 79 ><DIV
77 CLASS="SECT2" 80 CLASS="SECT2"
78 ><H2 81 ><H2
79 CLASS="SECT2" 82 CLASS="SECT2"
80 ><A 83 ><A
81 NAME="AEN271" 84 NAME="AEN271"
82 >Keyboard Related Structures</A 85 ></A
83 ></H2 86 >Keyboard Related Structures</H2
84 ><P 87 ><P
85 >It should make it a lot easier to understand this tutorial is you are familiar with the data types involved in keyboard access, so I'll explain them first.</P 88 >It should make it a lot easier to understand this tutorial is you are familiar with the data types involved in keyboard access, so I'll explain them first.</P
86 ><DIV 89 ><DIV
87 CLASS="SECT3" 90 CLASS="SECT3"
88 ><H3 91 ><H3
89 CLASS="SECT3" 92 CLASS="SECT3"
90 ><A 93 ><A
91 NAME="AEN274" 94 NAME="AEN274"
92 >SDLKey</A 95 ></A
93 ></H3 96 >SDLKey</H3
94 ><P 97 ><P
95 ><SPAN 98 ><SPAN
96 CLASS="STRUCTNAME" 99 CLASS="STRUCTNAME"
97 >SDLKey</SPAN 100 >SDLKey</SPAN
98 > is an enumerated type defined in SDL/include/SDL_keysym.h and detailed <A 101 > is an enumerated type defined in SDL/include/SDL_keysym.h and detailed <A
113 CLASS="SECT3" 116 CLASS="SECT3"
114 ><H3 117 ><H3
115 CLASS="SECT3" 118 CLASS="SECT3"
116 ><A 119 ><A
117 NAME="AEN282" 120 NAME="AEN282"
118 >SDLMod</A 121 ></A
119 ></H3 122 >SDLMod</H3
120 ><P 123 ><P
121 >SDLMod is an enumerated type, similar to <SPAN 124 >SDLMod is an enumerated type, similar to <SPAN
122 CLASS="STRUCTNAME" 125 CLASS="STRUCTNAME"
123 >SDLKey</SPAN 126 >SDLKey</SPAN
124 >, however it enumerates keyboard modifiers (Control, Alt, Shift). The full list of modifier symbols is <A 127 >, however it enumerates keyboard modifiers (Control, Alt, Shift). The full list of modifier symbols is <A
133 CLASS="SECT3" 136 CLASS="SECT3"
134 ><H3 137 ><H3
135 CLASS="SECT3" 138 CLASS="SECT3"
136 ><A 139 ><A
137 NAME="AEN288" 140 NAME="AEN288"
138 >SDL_keysym</A 141 ></A
139 ></H3 142 >SDL_keysym</H3
140 ><PRE 143 ><PRE
141 CLASS="PROGRAMLISTING" 144 CLASS="PROGRAMLISTING"
142 >typedef struct{ 145 >typedef struct{
143 Uint8 scancode; 146 Uint8 scancode;
144 SDLKey sym; 147 SDLKey sym;
214 CLASS="SECT3" 217 CLASS="SECT3"
215 ><H3 218 ><H3
216 CLASS="SECT3" 219 CLASS="SECT3"
217 ><A 220 ><A
218 NAME="AEN307" 221 NAME="AEN307"
219 >SDL_KeyboardEvent</A 222 ></A
220 ></H3 223 >SDL_KeyboardEvent</H3
221 ><PRE 224 ><PRE
222 CLASS="PROGRAMLISTING" 225 CLASS="PROGRAMLISTING"
223 >typedef struct{ 226 >typedef struct{
224 Uint8 type; 227 Uint8 type;
225 Uint8 state; 228 Uint8 state;
282 CLASS="SECT2" 285 CLASS="SECT2"
283 ><H2 286 ><H2
284 CLASS="SECT2" 287 CLASS="SECT2"
285 ><A 288 ><A
286 NAME="AEN324" 289 NAME="AEN324"
287 >Reading Keyboard Events</A 290 ></A
288 ></H2 291 >Reading Keyboard Events</H2
289 ><P 292 ><P
290 >Reading keybaord events from the event queue is quite simple (the event queue and using it is described <A 293 >Reading keybaord events from the event queue is quite simple (the event queue and using it is described <A
291 HREF="sdlevent.html" 294 HREF="sdlevent.html"
292 >here</A 295 >here</A
293 >). We read events using <A 296 >). We read events using <A
351 CLASS="SECT2" 354 CLASS="SECT2"
352 ><H2 355 ><H2
353 CLASS="SECT2" 356 CLASS="SECT2"
354 ><A 357 ><A
355 NAME="AEN338" 358 NAME="AEN338"
356 >A More Detailed Look</A 359 ></A
357 ></H2 360 >A More Detailed Look</H2
358 ><P 361 ><P
359 >Before we can read events SDL must be initialised with <A 362 >Before we can read events SDL must be initialised with <A
360 HREF="sdlinit.html" 363 HREF="sdlinit.html"
361 ><TT 364 ><TT
362 CLASS="FUNCTION" 365 CLASS="FUNCTION"
527 CLASS="SECT2" 530 CLASS="SECT2"
528 ><H2 531 ><H2
529 CLASS="SECT2" 532 CLASS="SECT2"
530 ><A 533 ><A
531 NAME="AEN354" 534 NAME="AEN354"
532 >Game-type Input</A 535 ></A
533 ></H2 536 >Game-type Input</H2
534 ><P 537 ><P
535 >I have found that people using keyboard events for games and other interactive applications don't always understand one fundemental point.</P 538 >I have found that people using keyboard events for games and other interactive applications don't always understand one fundemental point.</P
536 ><A 539 ><A
537 NAME="AEN357" 540 NAME="AEN357"
538 ></A 541 ></A
539 ><BLOCKQUOTE 542 ><BLOCKQUOTE
540 CLASS="BLOCKQUOTE" 543 CLASS="BLOCKQUOTE"
541 ><P 544 ><P
542 >Keyboard events <I 545 >Keyboard events <SPAN
546 CLASS="emphasis"
547 ><I
543 CLASS="EMPHASIS" 548 CLASS="EMPHASIS"
544 >only</I 549 >only</I
550 ></SPAN
545 > take place when a keys state changes from being unpressed to pressed, and vice versa.</P 551 > take place when a keys state changes from being unpressed to pressed, and vice versa.</P
546 ></BLOCKQUOTE 552 ></BLOCKQUOTE
547 ><P 553 ><P
548 >Imagine you have an image of an alien that you wish to move around using the cursor keys - when you pressed the left arrow key you want him to slide over to the left, when you press the down key you want him to slide down the screen. Examine the following code, it highlights and error that many people have made. 554 >Imagine you have an image of an alien that you wish to move around using the cursor keys: when you pressed the left arrow key you want him to slide over to the left, and when you press the down key you want him to slide down the screen. Examine the following code; it highlights an error that many people have made.
549 <PRE 555 <PRE
550 CLASS="PROGRAMLISTING" 556 CLASS="PROGRAMLISTING"
551 > /* Alien screen coordinates */ 557 > /* Alien screen coordinates */
552 int alien_x=0, alien_y=0; 558 int alien_x=0, alien_y=0;
553 . 559 .
676 ><DIV 682 ><DIV
677 CLASS="NAVFOOTER" 683 CLASS="NAVFOOTER"
678 ><HR 684 ><HR
679 ALIGN="LEFT" 685 ALIGN="LEFT"
680 WIDTH="100%"><TABLE 686 WIDTH="100%"><TABLE
687 SUMMARY="Footer navigation table"
681 WIDTH="100%" 688 WIDTH="100%"
682 BORDER="0" 689 BORDER="0"
683 CELLPADDING="0" 690 CELLPADDING="0"
684 CELLSPACING="0" 691 CELLSPACING="0"
685 ><TR 692 ><TR
687 WIDTH="33%" 694 WIDTH="33%"
688 ALIGN="left" 695 ALIGN="left"
689 VALIGN="top" 696 VALIGN="top"
690 ><A 697 ><A
691 HREF="guideinput.html" 698 HREF="guideinput.html"
699 ACCESSKEY="P"
692 >Prev</A 700 >Prev</A
693 ></TD 701 ></TD
694 ><TD 702 ><TD
695 WIDTH="34%" 703 WIDTH="34%"
696 ALIGN="center" 704 ALIGN="center"
697 VALIGN="top" 705 VALIGN="top"
698 ><A 706 ><A
699 HREF="index.html" 707 HREF="index.html"
708 ACCESSKEY="H"
700 >Home</A 709 >Home</A
701 ></TD 710 ></TD
702 ><TD 711 ><TD
703 WIDTH="33%" 712 WIDTH="33%"
704 ALIGN="right" 713 ALIGN="right"
705 VALIGN="top" 714 VALIGN="top"
706 ><A 715 ><A
707 HREF="guideexamples.html" 716 HREF="guideexamples.html"
717 ACCESSKEY="N"
708 >Next</A 718 >Next</A
709 ></TD 719 ></TD
710 ></TR 720 ></TR
711 ><TR 721 ><TR
712 ><TD 722 ><TD
718 WIDTH="34%" 728 WIDTH="34%"
719 ALIGN="center" 729 ALIGN="center"
720 VALIGN="top" 730 VALIGN="top"
721 ><A 731 ><A
722 HREF="guideinput.html" 732 HREF="guideinput.html"
733 ACCESSKEY="U"
723 >Up</A 734 >Up</A
724 ></TD 735 ></TD
725 ><TD 736 ><TD
726 WIDTH="33%" 737 WIDTH="33%"
727 ALIGN="right" 738 ALIGN="right"