1readkey(3)                      Allegro manual                      readkey(3)
2
3
4

NAME

6       readkey  - Returns the next character from the keyboard buffer. Allegro
7       game programming library.
8

SYNOPSIS

10       #include <allegro.h>
11
12
13       int readkey();
14

DESCRIPTION

16       Returns the next character from the keyboard buffer, in  ASCII  format.
17       If the buffer is empty, it waits until a key is pressed. You can see if
18       there are queued keypresses with keypressed().
19
20       The low byte of the return value contains the ASCII code  of  the  key,
21       and  the high byte the scancode. The scancode remains the same whatever
22       the state of the shift, ctrl and alt keys,  while  the  ASCII  code  is
23       affected  by  shift  and  ctrl  in  the normal way (shift changes case,
24       ctrl+letter gives the position of that  letter  in  the  alphabet,  eg.
25       ctrl+A  =  1, ctrl+B = 2, etc). Pressing alt+key returns only the scan‐
26       code, with a zero ASCII code in the low byte. For example:
27
28          int val;
29          ...
30          val = readkey();
31          if ((val & 0xff) == 'd')     /* by ASCII code */
32             allegro_message("You pressed 'd'\n");
33
34          if ((val >> 8) == KEY_SPACE) /* by scancode */
35             allegro_message("You pressed Space\n");
36
37          if ((val & 0xff) == 3)       /* ctrl+letter */
38             allegro_message("You pressed Control+C\n");
39
40          if (val == (KEY_X << 8))     /* alt+letter */
41             allegro_message("You pressed Alt+X\n");
42
43       This function cannot return character values greater than 255.  If  you
44       need to read Unicode input, use ureadkey() instead.
45
46

SEE ALSO

48       install_keyboard(3), ureadkey(3), keypressed(3), clear_keybuf(3), simu‐
49       late_keypress(3)
50
51
52
53Allegro                          version 4.4.3                      readkey(3)
Impressum