El controlador de teclado de Allegro proporciona entrada con búffer y un conjunto de variables que guardan el estado actual de cada tecla. Fíjese que no es posible detectar correctamente todas y cada una de las combinaciones de teclas, debido al diseño del teclado del PC. Combinaciones de dos o tres teclas funcionarán bien, pero si presiona más, probablemente las extras serán ignoradas (exactamente qué combinaciones son posibles parecen variar de un teclado a otro).
int install_keyboard();
Instala el controlador de interrupciones de teclado de Allegro. Debe
llamarla antes de usar cualquier otra función de teclado. Una vez
instalado el controlador no podrá usar las llamadas a sistema o las
funciones de librería de C para acceder al teclado. Devuelve cero con
éxito, o un número negativo si hubo problemas (pero puede decidir si
quiere verificar el valor de retorno dado que es muy poco probable que
esta función falle). Tenga en cuenta que en algunas plataformas el teclado
no funcionará a no ser que haya activado un modo gráfico, incluso si esta
función devuelve cero antes de haber llamado a set_gfx_mode.
Relacionado con: keyboard_callback, keyboard_ucallback, keyboard_lowlevel_callback, remove_keyboard, poll_keyboard, key, keypressed, readkey, ureadkey, set_gfx_mode, Variables de configuración estándar, three_finger_flag, key_led_flag, set_leds, set_keyboard_rate.void remove_keyboard();
Relacionado con: install_keyboard, allegro_exit.void install_keyboard_hooks(int (*keypressed)(), int (*readkey)());
Relacionado con: install_keyboard, keypressed, readkey.int poll_keyboard();
Relacionado con: keyboard_needs_poll, install_keyboard, key, key_shifts.int keyboard_needs_poll();
Relacionado con: poll_keyboard, install_keyboard, key.extern volatile char key[KEY_MAX];
if (key[KEY_SPACE])
printf("La barra espaciadora está siendo pulsada\n");
Tenga en cuenta que se supone que el array representa qué teclas están físicamente apretadas y cuales nó, por lo que semánticamente sólo es de lectura.
Estos son los scancodes del teclado:
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
Relacionado con: install_keyboard, poll_keyboard, key_shifts.extern volatile int key_shifts;
KB_SHIFT_FLAG
KB_CTRL_FLAG
KB_ALT_FLAG
KB_LWIN_FLAG
KB_RWIN_FLAG
KB_MENU_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
Relacionado con: install_keyboard, poll_keyboard, key.int keypressed();
Relacionado con: install_keyboard, readkey, clear_keybuf, simulate_keypress.int readkey();
if ((readkey() & 0xff) == 'd') // por código ASCII
printf("Has pulsado 'd'\n");
if ((readkey() >> 8) == KEY_SPACE) // por código scancode
printf("Has pulsado Espacio\n");
if ((readkey() & 0xff) == 3) // ctrl+letter
printf("Has pulsado Control+C\n");
if (readkey() == (KEY_X << 8)) // alt+letter
printf("Has pulsado Alt+X\n");
Esta función no puede devolver carácteres mayores que 255. Si necesita
leer entradas Unicode use ureadkey() en vez de readkey()
Relacionado con: install_keyboard, ureadkey, keypressed, clear_keybuf, simulate_keypress.int ureadkey(int *scancode);
Relacionado con: install_keyboard, readkey, keypressed, clear_keybuf, simulate_ukeypress.int scancode_to_ascii(int scancode);
void simulate_keypress(int key);
Introduce una tecla en el buffer del teclado, como si el usuario la
hubiese pulsado. El parámetro está el mismo formato que el devuelto por
readkey().
Relacionado con: install_keyboard, simulate_ukeypress, keypressed, readkey.void simulate_ukeypress(int key, int scancode);
Relacionado con: install_keyboard, simulate_keypress, keypressed, ureadkey.extern int (*keyboard_callback)(int key);
Relacionado con: install_keyboard, readkey, ureadkey, keyboard_ucallback, keyboard_lowlevel_callback.extern int (*keyboard_ucallback)(int key, int *scancode);
Relacionado con: install_keyboard, readkey, ureadkey, keyboard_callback, keyboard_lowlevel_callback.extern void (*keyboard_lowlevel_callback)(int scancode);
Relacionado con: install_keyboard, keyboard_callback, keyboard_ucallback.void set_leds(int leds);
Relacionado con: install_keyboard, key_led_flag.void set_keyboard_rate(int delay, int repeat);
Relacionado con: install_keyboard, readkey, ureadkey.void clear_keybuf();
Relacionado con: install_keyboard, keypressed, readkey, ureadkey.extern int three_finger_flag;
Relacionado con: install_keyboard.extern int key_led_flag;
Relacionado con: install_keyboard, set_leds.