1keyboard_lowlevel_callback(3) Allegro manual keyboard_lowlevel_callback(3)
2
3
4
6 keyboard_lowlevel_callback - User specified low level keyboard event
7 handler. Allegro game programming library.
8
10 #include <allegro.h>
11
12
13 extern void (*keyboard_lowlevel_callback)(int scancode);
14
16 If set, this function is called by the keyboard handler in response to
17 every keyboard event, both presses (including keyboard repeat rate) and
18 releases. It will be passed a raw keyboard scancode byte (scancodes are
19 7 bits long), with the top bit (8th bit) clear if the key has been
20 pressed or set if it was released. This routine executes in an inter‐
21 rupt context, so it must be in locked memory. Example:
22
23 volatile int key_down, key_up;
24
25 void keypress_watcher(int scancode)
26 {
27 if (scancode & 0x80) {
28 key_up = 1;
29 } else {
30 key_down = 1;
31 }
32 } END_OF_FUNCTION(keypress_watcher)
33
34 ...
35
36 install_timer();
37 LOCK_FUNCTION(silence_g_key);
38 LOCK_VARIABLE(key_down);
39 LOCK_VARIABLE(key_up);
40 install_keyboard();
41 keyboard_lowlevel_callback = keypress_watcher;
42 /* Disable keyboard repeat to get typewriter effect. */
43 set_keyboard_rate(0, 0);
44
45 ...
46
47 while (game_loop) {
48 if (key_down) {
49 key_down = 0;
50 /* Play sample of typewriter key press. */
51 }
52 if (key_up) {
53 key_up = 0;
54 /* Play sample of typewriter key release. */
55 }
56 }
57
58
60 install_keyboard(3), keyboard_callback(3), keyboard_ucallback(3),
61 exkeys(3)
62
63
64
65Allegro version 4.4.3 keyboard_lowlevel_callback(3)