<!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> <title>Keyboard routines</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta name="generator" content="pandoc" /> <link rel="stylesheet" href="pandoc.css" type="text/css" /> <script type="text/javascript" src="autosuggest.js"></script> <script type="text/javascript" src="search_index.js"></script> </head> <body> <div class="sidebar"> <div><ul ><li ><a href="index.html" ><strong >Contents</strong ></a ></li ><li ><a href="config.html" >Configuration files</a ></li ><li ><a href="display.html" >Display</a ></li ><li ><a href="events.html" >Events</a ></li ><li ><a href="file.html" >File I/O</a ></li ><li ><a href="fshook.html" >Filesystem</a ></li ><li ><a href="fixed.html" >Fixed point math</a ></li ><li ><a href="graphics.html" >Graphics</a ></li ><li ><a href="joystick.html" >Joystick</a ></li ><li ><a href="keyboard.html" >Keyboard</a ></li ><li ><a href="memory.html" >Memory</a ></li ><li ><a href="mouse.html" >Mouse</a ></li ><li ><a href="path.html" >Path</a ></li ><li ><a href="state.html" >State</a ></li ><li ><a href="system.html" >System</a ></li ><li ><a href="threads.html" >Threads</a ></li ><li ><a href="time.html" >Time</a ></li ><li ><a href="timer.html" >Timer</a ></li ><li ><a href="transformations.html" >Transformations</a ></li ><li ><a href="utf8.html" >UTF-8</a ></li ><li ><a href="misc.html" >Miscellaneous</a ></li ><li ><a href="platform.html" >Platform-specific</a ></li ><li ><a href="direct3d.html" >Direct3D</a ></li ><li ><a href="opengl.html" >OpenGL</a ></div> </li ></ul ><div><ul ><li ><a href="index.html#addons" ><strong >Addons</strong ></a ></li ><li ><a href="audio.html" >Audio addon</a ></li ><li ><a href="acodec.html" >Audio codecs</a ></li ><li ><a href="color.html" >Color addon</a ></li ><li ><a href="font.html" >Font addons</a ></li ><li ><a href="image.html" >Image I/O addon</a ></li ><li ><a href="memfile.html" >Memfile addon</a ></li ><li ><a href="native_dialog.html" >Native dialogs addon</a ></li ><li ><a href="physfs.html" >PhysicsFS addon</a ></li ><li ><a href="primitives.html" >Primitives addon</a ></div> </li ></ul ><div class="searchbox"> <script type="text/javascript"> function on_search(index, control) { for (i = 0; i < search_index.length; i++) { if (search_index[i] == control.keywords[index]) { break; } } location.href = search_urls[i]; } </script>Search<br /> <input type="text" name="q" id="q" size="15" autocomplete="off" /><br /><script type="text/javascript"> new autosuggest("q", search_index, null, on_search); </script> </div> </div> <div class="content"> <h1 class="title">Keyboard routines</h1> <div id="TOC" ><ul ><li ><a href="#allegro_keyboard_state" >ALLEGRO_KEYBOARD_STATE</a ></li ><li ><a href="#key-codes" >Key codes</a ></li ><li ><a href="#keyboard-modifier-flags" >Keyboard modifier flags</a ></li ><li ><a href="#al_install_keyboard" >al_install_keyboard</a ></li ><li ><a href="#al_is_keyboard_installed" >al_is_keyboard_installed</a ></li ><li ><a href="#al_uninstall_keyboard" >al_uninstall_keyboard</a ></li ><li ><a href="#al_get_keyboard_state" >al_get_keyboard_state</a ></li ><li ><a href="#al_key_down" >al_key_down</a ></li ><li ><a href="#al_keycode_to_name" >al_keycode_to_name</a ></li ><li ><a href="#al_set_keyboard_leds" >al_set_keyboard_leds</a ></li ><li ><a href="#al_get_keyboard_event_source" >al_get_keyboard_event_source</a ></li ></ul ></div > <p >These functions are declared in the main Allegro header file:</p ><pre ><code >#include <allegro5/allegro.h> </code ></pre ><h1 id="allegro_keyboard_state" ><a href="#TOC" >ALLEGRO_KEYBOARD_STATE</a ></h1 ><pre ><code >typedef struct ALLEGRO_KEYBOARD_STATE ALLEGRO_KEYBOARD_STATE; </code ></pre ><p >This is a structure that is used to hold a "snapshot" of a keyboard's state at a particular instant. It contains the following publically readable fields:</p ><ul ><li >display - points to the display that had keyboard focus at the time the state was saved. If no display was focused, this points to NULL.</li ></ul ><p >You cannot read the state of keys directly. Use the function <a href="keyboard.html#al_key_down" >al_key_down</a >.</p ><h1 id="key-codes" ><a href="#TOC" >Key codes</a ></h1 ><p >The constant ALLEGRO_KEY_MAX is always one higher than the highest key code. So if you want to use the key code as array index you can do something like this:</p ><pre ><code >bool pressed_keys[ALLEGRO_KEY_MAX]; ... pressed_keys[key_code] = true; </code ></pre ><p >These are the list of key codes used by Allegro, which are returned in the event.keyboard.keycode field of the ALLEGRO_KEY_DOWN and ALLEGRO_KEY_UP events and which you can pass to <a href="keyboard.html#al_key_down" >al_key_down</a >:</p ><pre ><code >ALLEGRO_KEY_A ... ALLEGRO_KEY_Z, ALLEGRO_KEY_0 ... ALLEGRO_KEY_9, ALLEGRO_KEY_PAD_0 ... ALLEGRO_KEY_PAD_9, ALLEGRO_KEY_F1 ... ALLEGRO_KEY_F12, ALLEGRO_KEY_ESCAPE, ALLEGRO_KEY_TILDE, ALLEGRO_KEY_MINUS, ALLEGRO_KEY_EQUALS, ALLEGRO_KEY_BACKSPACE, ALLEGRO_KEY_TAB, ALLEGRO_KEY_OPENBRACE, ALLEGRO_KEY_CLOSEBRACE, ALLEGRO_KEY_ENTER, ALLEGRO_KEY_SEMICOLON, ALLEGRO_KEY_QUOTE, ALLEGRO_KEY_BACKSLASH, ALLEGRO_KEY_BACKSLASH2, ALLEGRO_KEY_COMMA, ALLEGRO_KEY_FULLSTOP, ALLEGRO_KEY_SLASH, ALLEGRO_KEY_SPACE, ALLEGRO_KEY_INSERT, ALLEGRO_KEY_DELETE, ALLEGRO_KEY_HOME, ALLEGRO_KEY_END, ALLEGRO_KEY_PGUP, ALLEGRO_KEY_PGDN, ALLEGRO_KEY_LEFT, ALLEGRO_KEY_RIGHT, ALLEGRO_KEY_UP, ALLEGRO_KEY_DOWN, ALLEGRO_KEY_PAD_SLASH, ALLEGRO_KEY_PAD_ASTERISK, ALLEGRO_KEY_PAD_MINUS, ALLEGRO_KEY_PAD_PLUS, ALLEGRO_KEY_PAD_DELETE, ALLEGRO_KEY_PAD_ENTER, ALLEGRO_KEY_PRINTSCREEN, ALLEGRO_KEY_PAUSE, ALLEGRO_KEY_ABNT_C1, ALLEGRO_KEY_YEN, ALLEGRO_KEY_KANA, ALLEGRO_KEY_CONVERT, ALLEGRO_KEY_NOCONVERT, ALLEGRO_KEY_AT, ALLEGRO_KEY_CIRCUMFLEX, ALLEGRO_KEY_COLON2, ALLEGRO_KEY_KANJI, ALLEGRO_KEY_LSHIFT, ALLEGRO_KEY_RSHIFT, ALLEGRO_KEY_LCTRL, ALLEGRO_KEY_RCTRL, ALLEGRO_KEY_ALT, ALLEGRO_KEY_ALTGR, ALLEGRO_KEY_LWIN, ALLEGRO_KEY_RWIN, ALLEGRO_KEY_MENU, ALLEGRO_KEY_SCROLLLOCK, ALLEGRO_KEY_NUMLOCK, ALLEGRO_KEY_CAPSLOCK ALLEGRO_KEY_PAD_EQUALS, ALLEGRO_KEY_BACKQUOTE, ALLEGRO_KEY_SEMICOLON2, ALLEGRO_KEY_COMMAND </code ></pre ><h1 id="keyboard-modifier-flags" ><a href="#TOC" >Keyboard modifier flags</a ></h1 ><pre ><code >ALLEGRO_KEYMOD_SHIFT ALLEGRO_KEYMOD_CTRL ALLEGRO_KEYMOD_ALT ALLEGRO_KEYMOD_LWIN ALLEGRO_KEYMOD_RWIN ALLEGRO_KEYMOD_MENU ALLEGRO_KEYMOD_ALTGR ALLEGRO_KEYMOD_COMMAND ALLEGRO_KEYMOD_SCROLLLOCK ALLEGRO_KEYMOD_NUMLOCK ALLEGRO_KEYMOD_CAPSLOCK ALLEGRO_KEYMOD_INALTSEQ ALLEGRO_KEYMOD_ACCENT1 ALLEGRO_KEYMOD_ACCENT2 ALLEGRO_KEYMOD_ACCENT3 ALLEGRO_KEYMOD_ACCENT4 </code ></pre ><p >The event field 'keyboard.modifiers' is a bitfield composed of these constants. These indicate the modifier keys which were pressed at the time a character was typed.</p ><h1 id="al_install_keyboard" ><a href="#TOC" >al_install_keyboard</a ></h1 ><pre ><code >bool al_install_keyboard(void) </code ></pre ><p >Install a keyboard driver. Returns true if successful. If a driver was already installed, nothing happens and true is returned.</p ><p >See also: <a href="keyboard.html#al_uninstall_keyboard" >al_uninstall_keyboard</a >, <a href="keyboard.html#al_is_keyboard_installed" >al_is_keyboard_installed</a ></p ><h1 id="al_is_keyboard_installed" ><a href="#TOC" >al_is_keyboard_installed</a ></h1 ><pre ><code >bool al_is_keyboard_installed(void) </code ></pre ><p >Returns true if <a href="keyboard.html#al_install_keyboard" >al_install_keyboard</a > was called successfully.</p ><h1 id="al_uninstall_keyboard" ><a href="#TOC" >al_uninstall_keyboard</a ></h1 ><pre ><code >void al_uninstall_keyboard(void) </code ></pre ><p >Uninstalls the active keyboard driver, if any. This will automatically unregister the keyboard event source with any event queues.</p ><p >This function is automatically called when Allegro is shut down.</p ><p >See also: <a href="keyboard.html#al_install_keyboard" >al_install_keyboard</a ></p ><h1 id="al_get_keyboard_state" ><a href="#TOC" >al_get_keyboard_state</a ></h1 ><pre ><code >void al_get_keyboard_state(ALLEGRO_KEYBOARD_STATE *ret_state) </code ></pre ><p >Save the state of the keyboard specified at the time the function is called into the structure pointed to by <em >ret_state</em >.</p ><p >See also: <a href="keyboard.html#al_key_down" >al_key_down</a >, <a href="keyboard.html#allegro_keyboard_state" >ALLEGRO_KEYBOARD_STATE</a ></p ><h1 id="al_key_down" ><a href="#TOC" >al_key_down</a ></h1 ><pre ><code >bool al_key_down(const ALLEGRO_KEYBOARD_STATE *state, int keycode) </code ></pre ><p >Return true if the key specified was held down in the state specified.</p ><p >See also: <a href="keyboard.html#allegro_keyboard_state" >ALLEGRO_KEYBOARD_STATE</a ></p ><h1 id="al_keycode_to_name" ><a href="#TOC" >al_keycode_to_name</a ></h1 ><pre ><code >const char *al_keycode_to_name(int keycode) </code ></pre ><p >Converts the given keycode to a description of the key.</p ><h1 id="al_set_keyboard_leds" ><a href="#TOC" >al_set_keyboard_leds</a ></h1 ><pre ><code >bool al_set_keyboard_leds(int leds) </code ></pre ><p >Overrides the state of the keyboard LED indicators. Set to -1 to return to default behavior. False is returned if the current keyboard driver cannot set LED indicators.</p ><h1 id="al_get_keyboard_event_source" ><a href="#TOC" >al_get_keyboard_event_source</a ></h1 ><pre ><code >ALLEGRO_EVENT_SOURCE *al_get_keyboard_event_source(void) </code ></pre ><p >Retrieve the keyboard event source.</p ><p >Returns NULL if the keyboard subsystem was not installed.</p > <p class="timestamp"> Allegro version 5.0.3 - Last updated: 2011-05-22 02:32:06 UTC </p> </div> </body> </html>