summaryrefslogtreecommitdiff
path: root/Kernel/Keyboard.cpp
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2019-01-21 07:05:31 +0100
committerAndreas Kling <awesomekling@gmail.com>2019-01-21 07:27:26 +0100
commitaefbbeb3cb1decfe7e8c5e331e4c7a9bd8668710 (patch)
tree0fac76ef525b83727cd7829225238a6c4db3edce /Kernel/Keyboard.cpp
parent76a28817931e6826a6f406a6b677082aa8c4f949 (diff)
downloadserenity-aefbbeb3cb1decfe7e8c5e331e4c7a9bd8668710.zip
Flesh out keyboard event support a bit more.
Diffstat (limited to 'Kernel/Keyboard.cpp')
-rw-r--r--Kernel/Keyboard.cpp97
1 files changed, 62 insertions, 35 deletions
diff --git a/Kernel/Keyboard.cpp b/Kernel/Keyboard.cpp
index ecbd936346..6181d00ed3 100644
--- a/Kernel/Keyboard.cpp
+++ b/Kernel/Keyboard.cpp
@@ -19,52 +19,85 @@
#define MOD_CTRL 2
#define MOD_SHIFT 4
-static char map[0x100] =
+static char map[0x80] =
{
0, 0, '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '=', 0x08, 0,
- 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', '[', ']', 0, 0,
+ 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', '[', ']', '\n', 0,
'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', '\'', '`', 0, '\\',
'z', 'x', 'c', 'v', 'b', 'n', 'm', ',', '.', '/',
0, 0, 0, ' '
};
-static char shift_map[0x100] =
+static char shift_map[0x80] =
{
0, 0, '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '_', '+', 0, 0,
- 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', '{', '}', 0, 0,
+ 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', '{', '}', '\n', 0,
'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', ':', '"', '~', 0, '|',
'Z', 'X', 'C', 'V', 'B', 'N', 'M', '<', '>', '?',
0, 0, 0, ' '
};
-void Keyboard::emit(byte ch)
+static KeyCode unshifted_key_map[0x80] =
{
- Key key;
- key.character = ch;
- key.modifiers = m_modifiers;
+ Key_Invalid, Key_Invalid,
+ Key_1, Key_2, Key_3, Key_4, Key_5, Key_6, Key_7, Key_8, Key_9, Key_0, Key_Minus, Key_Equal, Key_Backspace,
+ Key_Invalid, //15
+ Key_Q, Key_W, Key_E, Key_R, Key_T, Key_Y, Key_U, Key_I, Key_O, Key_P, Key_LeftBracket, Key_RightBracket,
+ Key_Return, // 28
+ Key_Control, // 29
+ Key_A, Key_S, Key_D, Key_F, Key_G, Key_H, Key_J, Key_K, Key_L, Key_Semicolon, Key_Apostrophe, Key_Backtick,
+ Key_Shift,
+ Key_Backslash,
+ Key_Z, Key_X, Key_C, Key_V, Key_B, Key_N, Key_M, Key_Comma, Key_Period, Key_Slash,
+ Key_Alt,
+ Key_Invalid, Key_Invalid,
+ Key_Space
+};
+
+static KeyCode shifted_key_map[0x100] =
+{
+ Key_Invalid, Key_Invalid,
+ Key_ExclamationPoint, Key_AtSign, Key_Hashtag, Key_Dollar, Key_Percent, Key_Circumflex, Key_Ampersand, Key_Asterisk, Key_LeftParen, Key_RightParen, Key_Underscore, Key_Plus, Key_Backspace,
+ Key_Invalid,
+ Key_Q, Key_W, Key_E, Key_R, Key_T, Key_Y, Key_U, Key_I, Key_O, Key_P, Key_LeftBrace, Key_RightBrace,
+ Key_Return,
+ Key_Control,
+ Key_A, Key_S, Key_D, Key_F, Key_G, Key_H, Key_J, Key_K, Key_L, Key_Colon, Key_DoubleQuote, Key_Tilde,
+ Key_Shift,
+ Key_Pipe,
+ Key_Z, Key_X, Key_C, Key_V, Key_B, Key_N, Key_M, Key_LessThan, Key_GreaterThan, Key_QuestionMark,
+ Key_Alt,
+ Key_Invalid, Key_Invalid,
+ Key_Space
+};
+
+
+void Keyboard::key_state_changed(byte raw, bool pressed)
+{
+ Event event;
+ event.key = (m_modifiers & Mod_Shift) ? shifted_key_map[raw] : unshifted_key_map[raw];
+ event.character = (m_modifiers & Mod_Shift) ? shift_map[raw] : map[raw];
+ event.flags = m_modifiers;
+ if (pressed)
+ event.flags |= Is_Press;
if (m_client)
- m_client->on_key_pressed(key);
- m_queue.enqueue(key);
+ m_client->on_key_pressed(event);
+ m_queue.enqueue(event);
}
void Keyboard::handle_irq()
{
while (IO::in8(0x64) & 1) {
- byte ch = IO::in8(0x60);
+ byte raw = IO::in8(0x60);
+ byte ch = raw & 0x7f;
+ bool pressed = !(raw & 0x80);
+
switch (ch) {
- case 0x38: m_modifiers |= Mod_Alt; break;
- case 0xB8: m_modifiers &= ~Mod_Alt; break;
- case 0x1D: m_modifiers |= Mod_Ctrl; break;
- case 0x9D: m_modifiers &= ~Mod_Ctrl; break;
- case 0x2A: m_modifiers |= Mod_Shift; break;
- case 0xAA: m_modifiers &= ~Mod_Shift; break;
- case 0x1C: /* enter */ emit('\n'); break;
- case 0xFA: /* i8042 ack */ break;
+ case 0x38: update_modifier(Mod_Alt, pressed); break;
+ case 0x1d: update_modifier(Mod_Ctrl, pressed); break;
+ case 0x2a: update_modifier(Mod_Shift, pressed); break;
+ case 0xfa: /* i8042 ack */ break;
default:
- if (ch & 0x80) {
- // key has been depressed
- break;
- }
if (m_modifiers & MOD_ALT) {
switch (map[ch]) {
case '1':
@@ -77,14 +110,8 @@ void Keyboard::handle_irq()
break;
}
}
- if (!m_modifiers)
- emit(map[ch]);
- else if (m_modifiers & Mod_Shift)
- emit(shift_map[ch]);
- else if (m_modifiers & Mod_Ctrl)
- emit(map[ch]);
- }
- //break;
+ key_state_changed(ch, pressed);
+ }
}
}
@@ -126,11 +153,11 @@ ssize_t Keyboard::read(Process&, byte* buffer, size_t size)
if (m_queue.is_empty())
break;
// Don't return partial data frames.
- if ((size - nread) < 2)
+ if ((size - nread) < sizeof(Event))
break;
- auto key = m_queue.dequeue();
- buffer[nread++] = key.character;
- buffer[nread++] = key.modifiers;
+ auto event = m_queue.dequeue();
+ memcpy(buffer, &event, sizeof(Event));
+ nread += sizeof(Event);
}
return nread;
}