From 5797b03ea26404c68007e2fe235a0a8b7c0a1635 Mon Sep 17 00:00:00 2001 From: Laurent Vivier Date: Mon, 22 Aug 2005 20:17:34 +0000 Subject: [PATCH] Manage keyboard --- second/keyboard.c | 63 +++++++++++++++++++++++++++++++++++++++++++++++ second/keyboard.h | 16 ++++++++++++ 2 files changed, 79 insertions(+) create mode 100644 second/keyboard.c create mode 100644 second/keyboard.h diff --git a/second/keyboard.c b/second/keyboard.c new file mode 100644 index 0000000..e8a32a0 --- /dev/null +++ b/second/keyboard.c @@ -0,0 +1,63 @@ +/* + * + * (c) 2005 Laurent Vivier + * + */ + +#include "misc.h" +#include "glue.h" +#include "keyboard.h" + +#define test_bit(n,m) (((char*)(m))[(n) / 8] & (1L << (n % 8))) + +enum keycode { + keycode_command = 0x37, + keycode_shift = 0x38, + keycode_capslock = 0x39, + keycode_option = 0x3A, + keycode_control = 0x3B, + + keycode_last = 0x80 +}; + +void keyboard_get_key(int *modifiers, int *code) +{ + KeyMap keyboard; + int keycode; + + GetKeys(keyboard); + + /* modifier keys */ + + *modifiers = 0; + if (test_bit(keycode_command, keyboard)) + *modifiers |= modifiers_command; + if (test_bit(keycode_shift, keyboard)) + *modifiers |= modifiers_command; + if (test_bit(keycode_capslock, keyboard)) + *modifiers |= modifiers_command; + if (test_bit(keycode_option, keyboard)) + *modifiers |= modifiers_command; + if (test_bit(keycode_control, keyboard)) + *modifiers |= modifiers_command; + + /* other keys */ + + for (keycode = 0; keycode < keycode_last; keycode++) + { + /* modifiers */ + + if ( (keycode == keycode_command) || + (keycode == keycode_shift) || + (keycode == keycode_capslock) || + (keycode == keycode_option) || + (keycode == keycode_control) ) + continue; + + /* other keys */ + + if (test_bit(keycode, keyboard)) + break; + } + *code = keycode; +} diff --git a/second/keyboard.h b/second/keyboard.h new file mode 100644 index 0000000..00ba8a8 --- /dev/null +++ b/second/keyboard.h @@ -0,0 +1,16 @@ +/* + * + * (c) 2005 Laurent Vivier + * + */ + + +enum modifiers_mask { + modifiers_command = 0x01, + modifiers_shift = 0x02, + modifiers_capslock = 0x04, + modifiers_option = 0x08, + modifiers_control = 0x10, +}; + +extern void keyboard_get_key(int *modifiers, int *code);