Mercurial > pygame
view docs/ref/key.html @ 3172:d1b367fc08bc tests-returncode
Use a return code of 1 when the tests fail.
| author | Thomas Kluyver <takowl@gmail.com> |
|---|---|
| date | Wed, 09 Jan 2013 10:13:57 +0000 |
| parents | 0a3be7313aa4 |
| children |
line wrap: on
line source
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>pygame.key — Pygame v1.9.2 documentation</title> <link rel="stylesheet" href="../_static/pygame.css" type="text/css" /> <link rel="stylesheet" href="../_static/pygments.css" type="text/css" /> <script type="text/javascript"> var DOCUMENTATION_OPTIONS = { URL_ROOT: '../', VERSION: '1.9.2', COLLAPSE_INDEX: false, FILE_SUFFIX: '.html', HAS_SOURCE: true }; </script> <script type="text/javascript" src="../_static/jquery.js"></script> <script type="text/javascript" src="../_static/underscore.js"></script> <script type="text/javascript" src="../_static/doctools.js"></script> <link rel="shortcut icon" href="../_static/pygame.ico"/> <link rel="top" title="Pygame v1.9.2 documentation" href="../index.html" /> <link rel="next" title="pygame.locals" href="locals.html" /> <link rel="prev" title="pygame.joystick" href="joystick.html" /> </head> <body> <div class="document"> <div class="header"> <table> <tr> <td class="logo"> <a href="http://www.pygame.org/"> <img src="../_static/pygame_tiny.png"/> </a> <h5>pygame documentation</h5> </td> <td class="pagelinks"> <p class="top"> || <a href="http://www.pygame.org/">Pygame Home</a> || <a href="../index.html">Help Contents</a> || <a href="../genindex.html">Reference Index</a> || </p> <p class="bottom"> <a href="camera.html">camera</a> || <a href="cdrom.html">cdrom</a> || <a href="color.html">Color</a> || <a href="cursors.html">cursors</a> || <a href="display.html">display</a> || <a href="draw.html">draw</a> || <a href="event.html">event</a> || <a href="examples.html">examples</a> || <a href="font.html">font</a> || <a href="freetype.html">freetype</a> || <a href="gfxdraw.html">gfxdraw</a> || <a href="image.html">image</a> || <a href="joystick.html">joystick</a> || <a href="key.html">key</a> || <a href="locals.html">locals</a> || <a href="mask.html">mask</a> || <a href="math.html">math</a> || <a href="midi.html">midi</a> || <a href="mixer.html">mixer</a> || <a href="mouse.html">mouse</a> || <a href="movie.html">movie</a> || <a href="music.html">music</a> || <a href="overlay.html">Overlay</a> || <a href="pixelarray.html">PixelArray</a> || <a href="pixelcopy.html">pixelcopy</a> || <a href="pygame.html">pygame</a> || <a href="rect.html">Rect</a> || <a href="scrap.html">scrap</a> || <a href="sndarray.html">sndarray</a> || <a href="sprite.html">sprite</a> || <a href="surface.html">Surface</a> || <a href="surfarray.html">surfarray</a> || <a href="tests.html">tests</a> || <a href="time.html">time</a> || <a href="transform.html">transform</a> || <a href="pygame.html#module-pygame.version">version</a> </p> </td> </tr> </table> </div> <div class="documentwrapper"> <div class="body"> <div class="sectionwrapper"> <div class="section" id="module-pygame.key"> <span id="pygame-key"></span><dl class="definition module"> <dt class="title module"> <tt class="docutils literal"><span class="pre">pygame.key</span></tt></dt> <dd><div class="line-block"> <div class="line"><span class="summaryline">pygame module to work with the keyboard</span></div> </div> <table border="1" class="toc docutils"> <colgroup> <col width="24%" /> <col width="1%" /> <col width="74%" /> </colgroup> <tbody valign="top"> <tr><td><a class="toc reference external" href="key.html#pygame.key.get_focused">pygame.key.get_focused</a></td> <td>—</td> <td>true if the display is receiving keyboard input from the system</td> </tr> <tr><td><a class="toc reference external" href="key.html#pygame.key.get_pressed">pygame.key.get_pressed</a></td> <td>—</td> <td>get the state of all keyboard buttons</td> </tr> <tr><td><a class="toc reference external" href="key.html#pygame.key.get_mods">pygame.key.get_mods</a></td> <td>—</td> <td>determine which modifier keys are being held</td> </tr> <tr><td><a class="toc reference external" href="key.html#pygame.key.set_mods">pygame.key.set_mods</a></td> <td>—</td> <td>temporarily set which modifier keys are pressed</td> </tr> <tr><td><a class="toc reference external" href="key.html#pygame.key.set_repeat">pygame.key.set_repeat</a></td> <td>—</td> <td>control how held keys are repeated</td> </tr> <tr><td><a class="toc reference external" href="key.html#pygame.key.get_repeat">pygame.key.get_repeat</a></td> <td>—</td> <td>see how held keys are repeated</td> </tr> <tr><td><a class="toc reference external" href="key.html#pygame.key.name">pygame.key.name</a></td> <td>—</td> <td>get the name of a key identifier</td> </tr> </tbody> </table> <p>This module contains functions for dealing with the keyboard.</p> <p>The event queue gets <tt class="docutils literal"><span class="pre">pygame.KEYDOWN</span></tt> and <tt class="docutils literal"><span class="pre">pygame.KEYUP</span></tt> events when the keyboard buttons are pressed and released. Both events have a key attribute that is a integer id representing every key on the keyboard.</p> <p>The <tt class="docutils literal"><span class="pre">pygame.KEYDOWN</span></tt> event has an additional attributes unicode, and scancode. unicode represents a single character string that is the fully translated character entered. This takes into account the shift and composition keys. scancode represents the platform specific key code. This could be different from keyboard to keyboard, but is useful for key selection of weird keys like the multimedia keys.</p> <p>There are many keyboard constants, they are used to represent keys on the keyboard. The following is a list of all keyboard constants</p> <div class="highlight-python"><pre>KeyASCII ASCII Common Name K_BACKSPACE \b backspace K_TAB \t tab K_CLEAR clear K_RETURN \r return K_PAUSE pause K_ESCAPE ^[ escape K_SPACE space K_EXCLAIM ! exclaim K_QUOTEDBL " quotedbl K_HASH # hash K_DOLLAR $ dollar K_AMPERSAND & ampersand K_QUOTE quote K_LEFTPAREN ( left parenthesis K_RIGHTPAREN ) right parenthesis K_ASTERISK * asterisk K_PLUS + plus sign K_COMMA , comma K_MINUS - minus sign K_PERIOD . period K_SLASH / forward slash K_0 0 0 K_1 1 1 K_2 2 2 K_3 3 3 K_4 4 4 K_5 5 5 K_6 6 6 K_7 7 7 K_8 8 8 K_9 9 9 K_COLON : colon K_SEMICOLON ; semicolon K_LESS < less-than sign K_EQUALS = equals sign K_GREATER > greater-than sign K_QUESTION ? question mark K_AT @ at K_LEFTBRACKET [ left bracket K_BACKSLASH \ backslash K_RIGHTBRACKET ] right bracket K_CARET ^ caret K_UNDERSCORE _ underscore K_BACKQUOTE ` grave K_a a a K_b b b K_c c c K_d d d K_e e e K_f f f K_g g g K_h h h K_i i i K_j j j K_k k k K_l l l K_m m m K_n n n K_o o o K_p p p K_q q q K_r r r K_s s s K_t t t K_u u u K_v v v K_w w w K_x x x K_y y y K_z z z K_DELETE delete K_KP0 keypad 0 K_KP1 keypad 1 K_KP2 keypad 2 K_KP3 keypad 3 K_KP4 keypad 4 K_KP5 keypad 5 K_KP6 keypad 6 K_KP7 keypad 7 K_KP8 keypad 8 K_KP9 keypad 9 K_KP_PERIOD . keypad period K_KP_DIVIDE / keypad divide K_KP_MULTIPLY * keypad multiply K_KP_MINUS - keypad minus K_KP_PLUS + keypad plus K_KP_ENTER \r keypad enter K_KP_EQUALS = keypad equals K_UP up arrow K_DOWN down arrow K_RIGHT right arrow K_LEFT left arrow K_INSERT insert K_HOME home K_END end K_PAGEUP page up K_PAGEDOWN page down K_F1 F1 K_F2 F2 K_F3 F3 K_F4 F4 K_F5 F5 K_F6 F6 K_F7 F7 K_F8 F8 K_F9 F9 K_F10 F10 K_F11 F11 K_F12 F12 K_F13 F13 K_F14 F14 K_F15 F15 K_NUMLOCK numlock K_CAPSLOCK capslock K_SCROLLOCK scrollock K_RSHIFT right shift K_LSHIFT left shift K_RCTRL right ctrl K_LCTRL left ctrl K_RALT right alt K_LALT left alt K_RMETA right meta K_LMETA left meta K_LSUPER left windows key K_RSUPER right windows key K_MODE mode shift K_HELP help K_PRINT print screen K_SYSREQ sysrq K_BREAK break K_MENU menu K_POWER power K_EURO euro</pre> </div> <p>The keyboard also has a list of modifier states that can be assembled bit bitwise ORing them together.</p> <div class="highlight-python"><div class="highlight"><pre><span class="n">KMOD_NONE</span><span class="p">,</span> <span class="n">KMOD_LSHIFT</span><span class="p">,</span> <span class="n">KMOD_RSHIFT</span><span class="p">,</span> <span class="n">KMOD_SHIFT</span><span class="p">,</span> <span class="n">KMOD_CAPS</span><span class="p">,</span> <span class="n">KMOD_LCTRL</span><span class="p">,</span> <span class="n">KMOD_RCTRL</span><span class="p">,</span> <span class="n">KMOD_CTRL</span><span class="p">,</span> <span class="n">KMOD_LALT</span><span class="p">,</span> <span class="n">KMOD_RALT</span><span class="p">,</span> <span class="n">KMOD_ALT</span><span class="p">,</span> <span class="n">KMOD_LMETA</span><span class="p">,</span> <span class="n">KMOD_RMETA</span><span class="p">,</span> <span class="n">KMOD_META</span><span class="p">,</span> <span class="n">KMOD_NUM</span><span class="p">,</span> <span class="n">KMOD_MODE</span> </pre></div> </div> <dl class="definition function"> <dt class="title" id="pygame.key.get_focused"> <tt class="descclassname">pygame.key.</tt><tt class="descname">get_focused</tt><big>(</big><big>)</big><a class="headerlink" href="#pygame.key.get_focused" title="Permalink to this definition">¶</a></dt> <dd><div class="line-block"> <div class="line"><span class="summaryline">true if the display is receiving keyboard input from the system</span></div> <div class="line"><span class="signature">get_focused() -> bool</span></div> </div> <p>This is true when the display window has keyboard focus from the system. If the display needs to ensure it does not lose keyboard focus, it can use <tt class="docutils literal"><span class="pre">pygame.event.set_grab()</span></tt> to grab all input.</p> </dd></dl> <dl class="definition function"> <dt class="title" id="pygame.key.get_pressed"> <tt class="descclassname">pygame.key.</tt><tt class="descname">get_pressed</tt><big>(</big><big>)</big><a class="headerlink" href="#pygame.key.get_pressed" title="Permalink to this definition">¶</a></dt> <dd><div class="line-block"> <div class="line"><span class="summaryline">get the state of all keyboard buttons</span></div> <div class="line"><span class="signature">get_pressed() -> bools</span></div> </div> <p>Returns a sequence of boolean values representing the state of every key on the keyboard. Use the key constant values to index the array. A True value means the that button is pressed.</p> <p>Getting the list of pushed buttons with this function is not the proper way to handle text entry from the user. You have no way to know the order of keys pressed, and rapidly pushed keys can be completely unnoticed between two calls to <tt class="docutils literal"><span class="pre">pygame.key.get_pressed()</span></tt>. There is also no way to translate these pushed keys into a fully translated character value. See the <tt class="docutils literal"><span class="pre">pygame.KEYDOWN</span></tt> events on the event queue for this functionality.</p> </dd></dl> <dl class="definition function"> <dt class="title" id="pygame.key.get_mods"> <tt class="descclassname">pygame.key.</tt><tt class="descname">get_mods</tt><big>(</big><big>)</big><a class="headerlink" href="#pygame.key.get_mods" title="Permalink to this definition">¶</a></dt> <dd><div class="line-block"> <div class="line"><span class="summaryline">determine which modifier keys are being held</span></div> <div class="line"><span class="signature">get_mods() -> int</span></div> </div> <p>Returns a single integer representing a bitmask of all the modifier keys being held. Using bitwise operators you can test if specific shift keys are pressed, the state of the capslock button, and more.</p> </dd></dl> <dl class="definition function"> <dt class="title" id="pygame.key.set_mods"> <tt class="descclassname">pygame.key.</tt><tt class="descname">set_mods</tt><big>(</big><big>)</big><a class="headerlink" href="#pygame.key.set_mods" title="Permalink to this definition">¶</a></dt> <dd><div class="line-block"> <div class="line"><span class="summaryline">temporarily set which modifier keys are pressed</span></div> <div class="line"><span class="signature">set_mods(int) -> None</span></div> </div> <p>Create a bitmask of the modifier constants you want to impose on your program.</p> </dd></dl> <dl class="definition function"> <dt class="title" id="pygame.key.set_repeat"> <tt class="descclassname">pygame.key.</tt><tt class="descname">set_repeat</tt><big>(</big><big>)</big><a class="headerlink" href="#pygame.key.set_repeat" title="Permalink to this definition">¶</a></dt> <dd><div class="line-block"> <div class="line"><span class="summaryline">control how held keys are repeated</span></div> <div class="line"><span class="signature">set_repeat() -> None</span></div> <div class="line"><span class="signature">set_repeat(delay, interval) -> None</span></div> </div> <p>When the keyboard repeat is enabled, keys that are held down will generate multiple <tt class="docutils literal"><span class="pre">pygame.KEYDOWN</span></tt> events. The delay is the number of milliseconds before the first repeated <tt class="docutils literal"><span class="pre">pygame.KEYDOWN</span></tt> will be sent. After that another <tt class="docutils literal"><span class="pre">pygame.KEYDOWN</span></tt> will be sent every interval milliseconds. If no arguments are passed the key repeat is disabled.</p> <p>When pygame is initialized the key repeat is disabled.</p> </dd></dl> <dl class="definition function"> <dt class="title" id="pygame.key.get_repeat"> <tt class="descclassname">pygame.key.</tt><tt class="descname">get_repeat</tt><big>(</big><big>)</big><a class="headerlink" href="#pygame.key.get_repeat" title="Permalink to this definition">¶</a></dt> <dd><div class="line-block"> <div class="line"><span class="summaryline">see how held keys are repeated</span></div> <div class="line"><span class="signature">get_repeat() -> (delay, interval)</span></div> </div> <p>When the keyboard repeat is enabled, keys that are held down will generate multiple <tt class="docutils literal"><span class="pre">pygame.KEYDOWN</span></tt> events. The delay is the number of milliseconds before the first repeated <tt class="docutils literal"><span class="pre">pygame.KEYDOWN</span></tt> will be sent. After that another <tt class="docutils literal"><span class="pre">pygame.KEYDOWN</span></tt> will be sent every interval milliseconds.</p> <p>When pygame is initialized the key repeat is disabled.</p> <p>New in pygame 1.8.</p> </dd></dl> <dl class="definition function"> <dt class="title" id="pygame.key.name"> <tt class="descclassname">pygame.key.</tt><tt class="descname">name</tt><big>(</big><big>)</big><a class="headerlink" href="#pygame.key.name" title="Permalink to this definition">¶</a></dt> <dd><div class="line-block"> <div class="line"><span class="summaryline">get the name of a key identifier</span></div> <div class="line"><span class="signature">name(key) -> string</span></div> </div> <p>Get the descriptive name of the button from a keyboard button id constant.</p> </dd></dl> </dd></dl> </div> </div> </div> </div> <div class="clearer"></div> </div> <div class="related"> <h3>Navigation</h3> <ul> <li class="right" style="margin-right: 10px"> <a href="../genindex.html" title="General Index" accesskey="I">index</a></li> <li class="right" > <a href="locals.html" title="pygame.locals" accesskey="N">next</a> |</li> <li class="right" > <a href="joystick.html" title="pygame.joystick" accesskey="P">previous</a> |</li> <li><a href="../index.html">Pygame v1.9.2 documentation</a> »</li> <script type="text/javascript" src="jquery.plugin.docscomments.js"></script> </ul> </div> <div class="footer"> © Copyright 2011, Pygame Developers. </div> </body> </html>
