readkey man page

readkey — Returns the next character from the keyboard buffer. Allegro game programming library.


#include <allegro.h>

int readkey();


Returns the next character from the keyboard buffer, in ASCII format. If  the buffer is empty, it waits until a key is pressed. You can see if there are queued keypresses with keypressed().

The low byte of the return value contains the ASCII code of the key, and the high byte the scancode. The scancode remains the same whatever the state of the shift, ctrl and alt keys, while the ASCII code is affected by shift and ctrl in the normal way (shift changes case, ctrl+letter gives the position of that letter in the alphabet, eg. ctrl+A = 1, ctrl+B = 2, etc). Pressing alt+key returns only the scancode, with a zero ASCII code in the low byte. For example:

   int val;
   val = readkey();
   if ((val & 0xff) == 'd')     /* by ASCII code */
      allegro_message("You pressed 'd'\n");
   if ((val >> 8) == KEY_SPACE) /* by scancode */
      allegro_message("You pressed Space\n");
   if ((val & 0xff) == 3)       /* ctrl+letter */
      allegro_message("You pressed Control+C\n");
   if (val == (KEY_X << 8))     /* alt+letter */
      allegro_message("You pressed Alt+X\n");

This function cannot return character values greater than 255. If you  need to read Unicode input, use ureadkey() instead.

See Also

install_keyboard(3), ureadkey(3), keypressed(3), clear_keybuf(3), simulate_keypress(3)

Referenced By

clear_keybuf(3), ex3d(3), exaccel(3), exbitmap(3), exconfig(3), exdata(3), exexedat(3), exfont(3), exhello(3), exjoy(3), exkeys(3), exmem(3), exmidi(3), exmouse(3), expackf(3), expat(3), exquat(3), exrotscl(3), exspline(3), exstream(3), exswitch(3), exsyscur(3), extimer(3), extruec(3), exxfade(3), exzbuf(3), install_keyboard(3), install_keyboard_hooks(3), keyboard_callback(3), keyboard_ucallback(3), keypressed(3), set_keyboard_rate(3), simulate_keypress(3), ureadkey(3).

version 4.4.2 Allegro manual