docs/html/guideinput.html
changeset 803 355632dca928
parent 181 e5bc29de3f0a
child 6238 fba40d9f4a73
equal deleted inserted replaced
802:3c609d54f100 803:355632dca928
     2 ><HEAD
     2 ><HEAD
     3 ><TITLE
     3 ><TITLE
     4 >Input handling</TITLE
     4 >Input handling</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="guidevideoopengl.html"
    48 HREF="guidevideoopengl.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="guideinputkeyboard.html"
    62 HREF="guideinputkeyboard.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
    68 ><DIV
    71 ><DIV
    69 CLASS="CHAPTER"
    72 CLASS="CHAPTER"
    70 ><H1
    73 ><H1
    71 ><A
    74 ><A
    72 NAME="GUIDEINPUT"
    75 NAME="GUIDEINPUT"
    73 >Chapter 3. Input handling</A
    76 ></A
    74 ></H1
    77 >Chapter 3. Input handling</H1
    75 ><DIV
    78 ><DIV
    76 CLASS="TOC"
    79 CLASS="TOC"
    77 ><DL
    80 ><DL
    78 ><DT
    81 ><DT
    79 ><B
    82 ><B
    95 CLASS="SECT1"
    98 CLASS="SECT1"
    96 ><H1
    99 ><H1
    97 CLASS="SECT1"
   100 CLASS="SECT1"
    98 ><A
   101 ><A
    99 NAME="GUIDEINPUTJOYSTICK"
   102 NAME="GUIDEINPUTJOYSTICK"
   100 >Handling Joysticks</A
   103 ></A
   101 ></H1
   104 >Handling Joysticks</H1
   102 ><DIV
   105 ><DIV
   103 CLASS="SECT2"
   106 CLASS="SECT2"
   104 ><H2
   107 ><H2
   105 CLASS="SECT2"
   108 CLASS="SECT2"
   106 ><A
   109 ><A
   107 NAME="AEN135"
   110 NAME="AEN135"
   108 >Initialization</A
   111 ></A
   109 ></H2
   112 >Initialization</H2
   110 ><P
   113 ><P
   111 >The first step in using a joystick in a SDL program is to initialize the Joystick subsystems of SDL. This done by passing the <TT
   114 >The first step in using a joystick in a SDL program is to initialize the Joystick subsystems of SDL. This done by passing the <TT
   112 CLASS="LITERAL"
   115 CLASS="LITERAL"
   113 >SDL_INIT_JOYSTICK</TT
   116 >SDL_INIT_JOYSTICK</TT
   114 > flag to <A
   117 > flag to <A
   142 CLASS="SECT2"
   145 CLASS="SECT2"
   143 ><H2
   146 ><H2
   144 CLASS="SECT2"
   147 CLASS="SECT2"
   145 ><A
   148 ><A
   146 NAME="AEN145"
   149 NAME="AEN145"
   147 >Querying</A
   150 ></A
   148 ></H2
   151 >Querying</H2
   149 ><P
   152 ><P
   150 >If we have reached this point then we can safely assume that the SDL library has been initialized and that the Joystick subsystem is active. We can now call some video and/or sound functions to get things going before we need the joystick. Eventually we have to make sure that there is actually a joystick to work with. It's wise to always check even if you know a joystick will be present on the system because it can also help detect when the joystick is unplugged. The function used to check for joysticks is <A
   153 >If we have reached this point then we can safely assume that the SDL library has been initialized and that the Joystick subsystem is active. We can now call some video and/or sound functions to get things going before we need the joystick. Eventually we have to make sure that there is actually a joystick to work with. It's wise to always check even if you know a joystick will be present on the system because it can also help detect when the joystick is unplugged. The function used to check for joysticks is <A
   151 HREF="sdlnumjoysticks.html"
   154 HREF="sdlnumjoysticks.html"
   152 ><TT
   155 ><TT
   153 CLASS="FUNCTION"
   156 CLASS="FUNCTION"
   189 CLASS="SECT2"
   192 CLASS="SECT2"
   190 ><H2
   193 ><H2
   191 CLASS="SECT2"
   194 CLASS="SECT2"
   192 ><A
   195 ><A
   193 NAME="AEN157"
   196 NAME="AEN157"
   194 >Opening a Joystick and Receiving Joystick Events</A
   197 ></A
   195 ></H2
   198 >Opening a Joystick and Receiving Joystick Events</H2
   196 ><P
   199 ><P
   197 >SDL's event driven architecture makes working with joysticks a snap.  Joysticks can trigger 4 different types of events:
   200 >SDL's event driven architecture makes working with joysticks a snap.  Joysticks can trigger 4 different types of events:
   198 <P
   201 <P
   199 ></P
   202 ></P
   200 ><TABLE
   203 ><TABLE
   431 CLASS="SECT2"
   434 CLASS="SECT2"
   432 ><H2
   435 ><H2
   433 CLASS="SECT2"
   436 CLASS="SECT2"
   434 ><A
   437 ><A
   435 NAME="AEN214"
   438 NAME="AEN214"
   436 >Advanced Joystick Functions</A
   439 ></A
   437 ></H2
   440 >Advanced Joystick Functions</H2
   438 ><P
   441 ><P
   439 >That takes care of the controls that you can count on being on every joystick under the sun, but there are a few extra things that SDL can support.  Joyballs are next on our list, they are alot like axis with a few minor differences.  Joyballs store relative changes unlike the the absolute postion stored in a axis event. Also one trackball event contains both the change in x and they change in y.  Our case for it is as follows:</P
   442 >That takes care of the controls that you can count on being on every joystick under the sun, but there are a few extra things that SDL can support.  Joyballs are next on our list, they are alot like axis with a few minor differences.  Joyballs store relative changes unlike the the absolute postion stored in a axis event. Also one trackball event contains both the change in x and they change in y.  Our case for it is as follows:</P
   440 ><DIV
   443 ><DIV
   441 CLASS="EXAMPLE"
   444 CLASS="EXAMPLE"
   442 ><A
   445 ><A
   567 >Example 3-8. Joystick Hat Events</B
   570 >Example 3-8. Joystick Hat Events</B
   568 ></P
   571 ></P
   569 ><PRE
   572 ><PRE
   570 CLASS="PROGRAMLISTING"
   573 CLASS="PROGRAMLISTING"
   571 >    case SDL_JOYHATMOTION:  /* Handle Hat Motion */
   574 >    case SDL_JOYHATMOTION:  /* Handle Hat Motion */
   572     if ( event.jhat.hat &#38; SDL_HAT_UP )
   575     if ( event.jhat.value &#38; SDL_HAT_UP )
   573     {
   576     {
   574         /* Do up stuff here */
   577         /* Do up stuff here */
   575     }
   578     }
   576 
   579 
   577     if ( event.jhat.hat &#38; SDL_HAT_LEFT )
   580     if ( event.jhat.value &#38; SDL_HAT_LEFT )
   578     {
   581     {
   579         /* Do left stuff here */
   582         /* Do left stuff here */
   580     }
   583     }
   581 
   584 
   582     if ( event.jhat.hat &#38; SDL_HAT_RIGHTDOWN )
   585     if ( event.jhat.value &#38; SDL_HAT_RIGHTDOWN )
   583     {
   586     {
   584         /* Do right and down together stuff here */
   587         /* Do right and down together stuff here */
   585     }
   588     }
   586     break;</PRE
   589     break;</PRE
   587 ></DIV
   590 ></DIV
   672 ><DIV
   675 ><DIV
   673 CLASS="NAVFOOTER"
   676 CLASS="NAVFOOTER"
   674 ><HR
   677 ><HR
   675 ALIGN="LEFT"
   678 ALIGN="LEFT"
   676 WIDTH="100%"><TABLE
   679 WIDTH="100%"><TABLE
       
   680 SUMMARY="Footer navigation table"
   677 WIDTH="100%"
   681 WIDTH="100%"
   678 BORDER="0"
   682 BORDER="0"
   679 CELLPADDING="0"
   683 CELLPADDING="0"
   680 CELLSPACING="0"
   684 CELLSPACING="0"
   681 ><TR
   685 ><TR
   683 WIDTH="33%"
   687 WIDTH="33%"
   684 ALIGN="left"
   688 ALIGN="left"
   685 VALIGN="top"
   689 VALIGN="top"
   686 ><A
   690 ><A
   687 HREF="guidevideoopengl.html"
   691 HREF="guidevideoopengl.html"
       
   692 ACCESSKEY="P"
   688 >Prev</A
   693 >Prev</A
   689 ></TD
   694 ></TD
   690 ><TD
   695 ><TD
   691 WIDTH="34%"
   696 WIDTH="34%"
   692 ALIGN="center"
   697 ALIGN="center"
   693 VALIGN="top"
   698 VALIGN="top"
   694 ><A
   699 ><A
   695 HREF="index.html"
   700 HREF="index.html"
       
   701 ACCESSKEY="H"
   696 >Home</A
   702 >Home</A
   697 ></TD
   703 ></TD
   698 ><TD
   704 ><TD
   699 WIDTH="33%"
   705 WIDTH="33%"
   700 ALIGN="right"
   706 ALIGN="right"
   701 VALIGN="top"
   707 VALIGN="top"
   702 ><A
   708 ><A
   703 HREF="guideinputkeyboard.html"
   709 HREF="guideinputkeyboard.html"
       
   710 ACCESSKEY="N"
   704 >Next</A
   711 >Next</A
   705 ></TD
   712 ></TD
   706 ></TR
   713 ></TR
   707 ><TR
   714 ><TR
   708 ><TD
   715 ><TD
   714 WIDTH="34%"
   721 WIDTH="34%"
   715 ALIGN="center"
   722 ALIGN="center"
   716 VALIGN="top"
   723 VALIGN="top"
   717 ><A
   724 ><A
   718 HREF="guide.html"
   725 HREF="guide.html"
       
   726 ACCESSKEY="U"
   719 >Up</A
   727 >Up</A
   720 ></TD
   728 ></TD
   721 ><TD
   729 ><TD
   722 WIDTH="33%"
   730 WIDTH="33%"
   723 ALIGN="right"
   731 ALIGN="right"