The Allegro keyboard handler provides both buffered input and a set of flags storing the current state of each key. Note that it is not possible to correctly detect every combination of keys, due to the design of the PC keyboard. Up to two or three keys at a time will work fine, but if you press more than that the extras are likely to be ignored (exactly which combinations are possible seems to vary from one keyboard to another).
See also: remove_keyboard, poll_keyboard, key, keypressed, readkey, ureadkey, keyboard_callback, keyboard_ucallback, keyboard_lowlevel_callback, three_finger_flag, key_led_flag, set_leds, set_keyboard_rate, set_gfx_mode, Standard config variables.
Examples using this: Available Allegro examples.
See also: install_keyboard, allegro_exit.
See also: install_keyboard, keypressed, readkey.
See also: keyboard_needs_poll, install_keyboard, key, key_shifts.
Examples using this: excamera, exsample, exstars.
See also: poll_keyboard, install_keyboard, key.
if (key[KEY_SPACE])
printf("Space is pressed\n");
Note that the array is supposed to represent which keys are physically held down and which keys are not, so it is semantically read-only.
These are the keyboard scancodes:
KEY_A ... KEY_Z,
KEY_0 ... KEY_9,
KEY_0_PAD ... KEY_9_PAD,
KEY_F1 ... KEY_F12,
KEY_ESC, KEY_TILDE, KEY_MINUS, KEY_EQUALS,
KEY_BACKSPACE, KEY_TAB, KEY_OPENBRACE, KEY_CLOSEBRACE,
KEY_ENTER, KEY_COLON, KEY_QUOTE, KEY_BACKSLASH,
KEY_BACKSLASH2, KEY_COMMA, KEY_STOP, KEY_SLASH,
KEY_SPACE,
KEY_INSERT, KEY_DEL, KEY_HOME, KEY_END, KEY_PGUP,
KEY_PGDN, KEY_LEFT, KEY_RIGHT, KEY_UP, KEY_DOWN,
KEY_SLASH_PAD, KEY_ASTERISK, KEY_MINUS_PAD,
KEY_PLUS_PAD, KEY_DEL_PAD, KEY_ENTER_PAD,
KEY_PRTSCR, KEY_PAUSE,
KEY_ABNT_C1, KEY_YEN, KEY_KANA, KEY_CONVERT, KEY_NOCONVERT,
KEY_AT, KEY_CIRCUMFLEX, KEY_COLON2, KEY_KANJI,
KEY_LSHIFT, KEY_RSHIFT,
KEY_LCONTROL, KEY_RCONTROL,
KEY_ALT, KEY_ALTGR,
KEY_LWIN, KEY_RWIN, KEY_MENU,
KEY_SCRLOCK, KEY_NUMLOCK, KEY_CAPSLOCK
KEY_EQUALS_PAD, KEY_BACKQUOTE, KEY_SEMICOLON, KEY_COMMAND
See also: install_keyboard, poll_keyboard, key_shifts.
Examples using this: Available Allegro examples.
KB_SHIFT_FLAG
KB_CTRL_FLAG
KB_ALT_FLAG
KB_LWIN_FLAG
KB_RWIN_FLAG
KB_MENU_FLAG
KB_COMMAND_FLAG
KB_SCROLOCK_FLAG
KB_NUMLOCK_FLAG
KB_CAPSLOCK_FLAG
KB_INALTSEQ_FLAG
KB_ACCENT1_FLAG
KB_ACCENT2_FLAG
KB_ACCENT3_FLAG
KB_ACCENT4_FLAG
See also: install_keyboard, poll_keyboard, key.
Examples using this: excamera, exkeys.
See also: install_keyboard, readkey, ureadkey, clear_keybuf, simulate_keypress, simulate_ukeypress.
Examples using this: Available Allegro examples.
if ((readkey() & 0xff) == 'd') // by ASCII code
printf("You pressed 'd'\n");
if ((readkey() >> 8) == KEY_SPACE) // by scancode
printf("You pressed Space\n");
if ((readkey() & 0xff) == 3) // ctrl+letter
printf("You pressed Control+C\n");
if (readkey() == (KEY_X << 8)) // alt+letter
printf("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, ureadkey, keypressed, clear_keybuf, simulate_keypress.
Examples using this: Available Allegro examples.
See also: install_keyboard, readkey, keypressed, clear_keybuf, simulate_ukeypress.
Examples using this: exkeys.
See also: install_keyboard, simulate_ukeypress, keypressed, readkey.
See also: install_keyboard, simulate_keypress, keypressed, ureadkey.
See also: install_keyboard, readkey, ureadkey, keyboard_ucallback, keyboard_lowlevel_callback.
See also: install_keyboard, readkey, ureadkey, keyboard_callback, keyboard_lowlevel_callback.
See also: install_keyboard, keyboard_callback, keyboard_ucallback.
See also: install_keyboard, key_led_flag.
See also: install_keyboard, readkey, ureadkey.
See also: install_keyboard, keypressed, readkey, ureadkey.
Examples using this: Available Allegro examples.
See also: install_keyboard.
See also: install_keyboard, set_leds.