Kernel: KeyEvent is now well known keycode

Keycodes are easier to handle as you need only one keyboard layout
for keycodes. Otherwise you would need to implement keyboard layout
for every keyboard driver in every language.
This commit is contained in:
Bananymous 2024-01-10 01:29:37 +02:00
parent e4f48cbc73
commit 961ab9768a
12 changed files with 981 additions and 489 deletions

View File

@ -32,6 +32,8 @@ set(KERNEL_SOURCES
kernel/FS/TmpFS/FileSystem.cpp
kernel/FS/TmpFS/Inode.cpp
kernel/FS/VirtualFileSystem.cpp
kernel/Input/KeyboardLayouts/FI.cpp
kernel/Input/KeyEvent.cpp
kernel/Input/PS2/Controller.cpp
kernel/Input/PS2/Device.cpp
kernel/Input/PS2/Keyboard.cpp

View File

@ -5,6 +5,47 @@
namespace Kernel::Input
{
/*
Key Code:
bits 4:0 column (from left)
bits 7:5 row (from top)
*/
#define BANAN_CONSTEVAL_STATIC_ASSERT(cond) do { int dummy = 1 / (cond); } while (false)
consteval uint8_t keycode_function(uint8_t index)
{
BANAN_CONSTEVAL_STATIC_ASSERT(index <= 0b11111);
return index;
}
consteval uint8_t keycode_normal(uint8_t row, uint8_t col)
{
BANAN_CONSTEVAL_STATIC_ASSERT(row <= 0b111 - 1);
BANAN_CONSTEVAL_STATIC_ASSERT(col < 0b11111 - 8);
return ((row + 1) << 5) | col;
}
consteval uint8_t keycode_numpad(uint8_t row, uint8_t col)
{
BANAN_CONSTEVAL_STATIC_ASSERT(row <= 0b111 - 1);
BANAN_CONSTEVAL_STATIC_ASSERT(col <= 8);
return ((row + 1) << 5) | (col + 0b11111 - 8);
}
enum ModifierKeycode
{
CapsLock = keycode_normal(2, 0),
NumLock = keycode_numpad(0, 0),
ScrollLock = keycode_function(20),
LShift = keycode_normal(3, 0),
RShift = keycode_normal(3, 12),
LCtrl = keycode_normal(4, 0),
RCtrl = keycode_normal(4, 5),
LAlt = keycode_normal(4, 2),
RAlt = keycode_normal(4, 4),
};
enum class Key
{
Invalid, None,
@ -14,9 +55,9 @@ namespace Kernel::Input
F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12,
Insert, PrintScreen, Delete, Home, End, PageUp, PageDown, Enter, Space,
ExclamationMark, DoubleQuote, Hashtag, Currency, Percent, Ampersand, Slash, Section, Half,
OpenBracet, CloseBracet, OpenBrace, CloseBrace, OpenCurlyBrace, CloseCurlyBrace,
Equals, QuestionMark, Plus, BackSlash, Acute, BackTick, TwoDots, Backspace, AtSign, Pound, Dollar, Euro,
Escape, Tab, CapsLock, LeftShift, LeftCtrl, Super, Alt, AltGr, RightCtrl, RightShift,
OpenParenthesis, CloseParenthesis, OpenSquareBracket, CloseSquareBracket, OpenCurlyBracket, CloseCurlyBracket,
Equals, QuestionMark, Plus, BackSlash, Acute, BackTick, TwoDots, Cedilla, Backspace, AtSign, Pound, Dollar, Euro,
Escape, Tab, CapsLock, LeftShift, LeftCtrl, Super, LeftAlt, RightAlt, AltGr = RightAlt, RightCtrl, RightShift,
SingleQuote, Asterix, Caret, Tilde, ArrowUp, ArrowDown, ArrowLeft, ArrowRight,
Comma, Semicolon, Period, Colon, Hyphen, Underscore, NumLock, ScrollLock, LessThan, GreaterThan, Pipe,
Numpad0, Numpad1, Numpad2, Numpad3, Numpad4, Numpad5, Numpad6, Numpad7, Numpad8, Numpad9,
@ -27,73 +68,44 @@ namespace Kernel::Input
struct KeyEvent
{
enum class Modifier : uint8_t
enum Modifier : uint16_t
{
Shift = (1 << 0),
Ctrl = (1 << 1),
Alt = (1 << 2),
AltGr = (1 << 3),
CapsLock = (1 << 4),
NumLock = (1 << 5),
ScrollLock = (1 << 6),
Released = (1 << 7),
LShift = (1 << 0),
RShift = (1 << 1),
LCtrl = (1 << 2),
RCtrl = (1 << 3),
LAlt = (1 << 4),
RAlt = (1 << 5),
CapsLock = (1 << 6),
NumLock = (1 << 7),
ScrollLock = (1 << 8),
Pressed = (1 << 9),
};
bool shift() const { return modifier & (uint8_t)Modifier::Shift; }
bool ctrl() const { return modifier & (uint8_t)Modifier::Ctrl; }
bool alt() const { return modifier & (uint8_t)Modifier::Alt; }
bool altgr() const { return modifier & (uint8_t)Modifier::AltGr; }
bool caps_lock() const { return modifier & (uint8_t)Modifier::CapsLock; }
bool num_lock() const { return modifier & (uint8_t)Modifier::NumLock; }
bool scroll_lock() const { return modifier & (uint8_t)Modifier::ScrollLock; }
bool released() const { return modifier & (uint8_t)Modifier::Released; }
bool pressed() const { return !released(); }
bool lshift() const { return modifier & Modifier::LShift; }
bool rshift() const { return modifier & Modifier::RShift; }
bool shift() const { return lshift() || rshift(); }
uint8_t modifier;
Key key;
bool lctrl() const { return modifier & Modifier::LCtrl; }
bool rctrl() const { return modifier & Modifier::RCtrl; }
bool ctrl() const { return lctrl() || rctrl(); }
bool lalt() const { return modifier & Modifier::LAlt; }
bool ralt() const { return modifier & Modifier::RAlt; }
bool alt() const { return lalt() || ralt(); }
bool caps_lock() const { return modifier & Modifier::CapsLock; }
bool num_lock() const { return modifier & Modifier::NumLock; }
bool scroll_lock() const { return modifier & Modifier::ScrollLock; }
bool pressed() const { return modifier & Modifier::Pressed; }
bool released() const { return !pressed(); }
uint16_t modifier;
uint8_t keycode;
};
inline const char* key_event_to_utf8(KeyEvent event)
{
static constexpr const char* utf8_lower[] = {
nullptr, nullptr,
"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z",
"å", "ä", "ö",
"0", "1", "2", "3", "4", "5", "6", "7", "8", "9",
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr,
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, " ",
"!", "\"", "#", "¤", "%", "&", "/", "§", "½",
"(", ")", "[", "]", "{", "}",
"=", "?", "+", "\\", "´", "`", "¨", nullptr, "@", "£", "$", "",
nullptr, "\t", nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr,
"'", "*", "^", "~", nullptr, nullptr, nullptr, nullptr,
",", ";", ".", ":", "-", "_", nullptr, nullptr, "<", ">", "|",
"0", "1", "2", "3", "4", "5", "6", "7", "8", "9",
"+", "-", "*", "/", nullptr, ",",
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr,
};
static_assert((size_t)Key::Count == sizeof(utf8_lower) / sizeof(*utf8_lower));
static constexpr const char* utf8_upper[] = {
nullptr, nullptr,
"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z",
"Å", "Ä", "Ö",
"0", "1", "2", "3", "4", "5", "6", "7", "8", "9",
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr,
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, " ",
"!", "\"", "#", "¤", "%", "&", "/", "§", "½",
"(", ")", "[", "]", "{", "}",
"=", "?", "+", "\\", "´", "`", "¨", nullptr, "@", "£", "$", "",
nullptr, "\t", nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr,
"'", "*", "^", "~", nullptr, nullptr, nullptr, nullptr,
",", ";", ".", ":", "-", "_", nullptr, nullptr, "<", ">", "|",
"0", "1", "2", "3", "4", "5", "6", "7", "8", "9",
"+", "-", "*", "/", nullptr, ",",
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr,
};
static_assert((size_t)Key::Count == sizeof(utf8_upper) / sizeof(*utf8_lower));
return (event.shift() ^ event.caps_lock()) ? utf8_upper[(uint8_t)event.key] : utf8_lower[(uint8_t)event.key];
}
Key key_event_to_key(KeyEvent);
const char* key_to_utf8(Key key, uint16_t modifier);
}

View File

@ -0,0 +1,8 @@
#pragma once
namespace Kernel::Input::KeyboardLayout
{
void initialize_fi();
}

View File

@ -78,13 +78,6 @@ namespace Kernel::Input::PS2
KEY_ERROR_OR_BUFFER_OVERRUN2 = 0xFF,
};
enum KBScancode : uint8_t
{
SET_SCANCODE_SET1 = 1,
SET_SCANCODE_SET2 = 2,
SET_SCANCODE_SET3 = 3,
};
enum KBLeds : uint8_t
{
SCROLL_LOCK = (1 << 0),

View File

@ -1,5 +1,7 @@
#pragma once
#include <BAN/Array.h>
#include <BAN/CircularQueue.h>
#include <kernel/Input/KeyEvent.h>
#include <kernel/Input/PS2/Device.h>
#include <kernel/Input/PS2/Keymap.h>
@ -14,7 +16,7 @@ namespace Kernel::Input
enum Command : uint8_t
{
SET_LEDS = 0xED,
SCANCODE = 0xF0
CONFIG_SCANCODE_SET = 0xF0
};
public:
@ -29,12 +31,14 @@ namespace Kernel::Input
void update_leds();
private:
uint8_t m_byte_buffer[10];
BAN::Array<uint8_t, 3> m_byte_buffer;
uint8_t m_byte_index { 0 };
uint8_t m_modifiers { 0 };
uint8_t m_scancode_set { 0xFF };
BAN::CircularQueue<KeyEvent, 10> m_event_queue;
uint16_t m_modifiers { 0 };
BAN::CircularQueue<KeyEvent, 50> m_event_queue;
PS2Keymap m_keymap;

View File

@ -1,7 +1,7 @@
#pragma once
#include <BAN/Vector.h>
#include <kernel/Input/KeyEvent.h>
#include <BAN/Array.h>
#include <BAN/Optional.h>
namespace Kernel::Input
{
@ -9,15 +9,18 @@ namespace Kernel::Input
class PS2Keymap
{
public:
PS2Keymap();
void initialize(uint8_t scancode_set);
Key key_for_scancode_and_modifiers(uint32_t, uint8_t);
BAN::Optional<uint8_t> get_keycode(uint8_t scancode, bool extended) const;
private:
BAN::Vector<Key> m_normal_keymap;
BAN::Vector<Key> m_shift_keymap;
BAN::Vector<Key> m_altgr_keymap;
BAN::Vector<Key> m_extended_keymap;
void initialize_scancode_set1();
void initialize_scancode_set2();
void initialize_scancode_set3();
private:
BAN::Array<uint8_t, 0xFF> m_scancode_to_keycode_normal;
BAN::Array<uint8_t, 0xFF> m_scancode_to_keycode_extended;
};
}

View File

@ -0,0 +1,64 @@
#include <BAN/Array.h>
#include <kernel/Input/KeyEvent.h>
namespace Kernel::Input
{
BAN::Array<Key, 0xFF> g_keycode_to_key_normal;
BAN::Array<Key, 0xFF> g_keycode_to_key_shift;
BAN::Array<Key, 0xFF> g_keycode_to_key_altgr;
Key key_event_to_key(KeyEvent event)
{
if (event.shift())
return g_keycode_to_key_shift[event.keycode];
if (event.ralt())
return g_keycode_to_key_altgr[event.keycode];
return g_keycode_to_key_normal[event.keycode];
}
const char* key_to_utf8(Key key, uint16_t modifier)
{
static constexpr const char* utf8_lower[] = {
nullptr, nullptr,
"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z",
"å", "ä", "ö",
"0", "1", "2", "3", "4", "5", "6", "7", "8", "9",
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr,
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, " ",
"!", "\"", "#", "¤", "%", "&", "/", "§", "½",
"(", ")", "[", "]", "{", "}",
"=", "?", "+", "\\", "´", "`", "¨", "¸", nullptr, "@", "£", "$", "",
nullptr, "\t", nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr,
"'", "*", "^", "~", nullptr, nullptr, nullptr, nullptr,
",", ";", ".", ":", "-", "_", nullptr, nullptr, "<", ">", "|",
"0", "1", "2", "3", "4", "5", "6", "7", "8", "9",
"+", "-", "*", "/", nullptr, ",",
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr,
};
static_assert((size_t)Key::Count == sizeof(utf8_lower) / sizeof(*utf8_lower));
static constexpr const char* utf8_upper[] = {
nullptr, nullptr,
"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z",
"Å", "Ä", "Ö",
"0", "1", "2", "3", "4", "5", "6", "7", "8", "9",
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr,
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, " ",
"!", "\"", "#", "¤", "%", "&", "/", "§", "½",
"(", ")", "[", "]", "{", "}",
"=", "?", "+", "\\", "´", "`", "¨", "¸", nullptr, "@", "£", "$", "",
nullptr, "\t", nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr,
"'", "*", "^", "~", nullptr, nullptr, nullptr, nullptr,
",", ";", ".", ":", "-", "_", nullptr, nullptr, "<", ">", "|",
"0", "1", "2", "3", "4", "5", "6", "7", "8", "9",
"+", "-", "*", "/", nullptr, ",",
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr,
};
static_assert((size_t)Key::Count == sizeof(utf8_upper) / sizeof(*utf8_lower));
KeyEvent event { .modifier = modifier, .keycode = 0x00 };
return (event.shift() ^ event.caps_lock()) ? utf8_upper[static_cast<uint8_t>(key)] : utf8_lower[static_cast<uint8_t>(key)];
}
}

View File

@ -0,0 +1,363 @@
#include <BAN/Array.h>
#include <kernel/Input/KeyEvent.h>
namespace Kernel::Input
{
extern BAN::Array<Key, 0xFF> g_keycode_to_key_normal;
extern BAN::Array<Key, 0xFF> g_keycode_to_key_shift;
extern BAN::Array<Key, 0xFF> g_keycode_to_key_altgr;
}
namespace Kernel::Input::KeyboardLayout
{
static void initialize_fi_normal();
static void initialize_fi_shift();
static void initialize_fi_altgr();
void initialize_fi()
{
for (auto& key : g_keycode_to_key_normal)
key = Key::None;
for (auto& key : g_keycode_to_key_shift)
key = Key::None;
for (auto& key : g_keycode_to_key_altgr)
key = Key::None;
initialize_fi_normal();
initialize_fi_shift();
initialize_fi_altgr();
}
static void initialize_fi_normal()
{
g_keycode_to_key_normal[keycode_normal(0, 0)] = Key::Section;
g_keycode_to_key_normal[keycode_normal(0, 1)] = Key::_1;
g_keycode_to_key_normal[keycode_normal(0, 2)] = Key::_2;
g_keycode_to_key_normal[keycode_normal(0, 3)] = Key::_3;
g_keycode_to_key_normal[keycode_normal(0, 4)] = Key::_4;
g_keycode_to_key_normal[keycode_normal(0, 5)] = Key::_5;
g_keycode_to_key_normal[keycode_normal(0, 6)] = Key::_6;
g_keycode_to_key_normal[keycode_normal(0, 7)] = Key::_7;
g_keycode_to_key_normal[keycode_normal(0, 8)] = Key::_8;
g_keycode_to_key_normal[keycode_normal(0, 9)] = Key::_9;
g_keycode_to_key_normal[keycode_normal(0, 10)] = Key::_0;
g_keycode_to_key_normal[keycode_normal(0, 11)] = Key::Plus;
g_keycode_to_key_normal[keycode_normal(0, 12)] = Key::Acute;
g_keycode_to_key_normal[keycode_normal(0, 13)] = Key::Backspace;
g_keycode_to_key_normal[keycode_normal(1, 0)] = Key::Tab;
g_keycode_to_key_normal[keycode_normal(1, 1)] = Key::Q;
g_keycode_to_key_normal[keycode_normal(1, 2)] = Key::W;
g_keycode_to_key_normal[keycode_normal(1, 3)] = Key::E;
g_keycode_to_key_normal[keycode_normal(1, 4)] = Key::R;
g_keycode_to_key_normal[keycode_normal(1, 5)] = Key::T;
g_keycode_to_key_normal[keycode_normal(1, 6)] = Key::Y;
g_keycode_to_key_normal[keycode_normal(1, 7)] = Key::U;
g_keycode_to_key_normal[keycode_normal(1, 8)] = Key::I;
g_keycode_to_key_normal[keycode_normal(1, 9)] = Key::O;
g_keycode_to_key_normal[keycode_normal(1, 10)] = Key::P;
g_keycode_to_key_normal[keycode_normal(1, 11)] = Key::A_Ring;
g_keycode_to_key_normal[keycode_normal(1, 12)] = Key::TwoDots;
g_keycode_to_key_normal[keycode_normal(2, 0)] = Key::CapsLock;
g_keycode_to_key_normal[keycode_normal(2, 1)] = Key::A;
g_keycode_to_key_normal[keycode_normal(2, 2)] = Key::S;
g_keycode_to_key_normal[keycode_normal(2, 3)] = Key::D;
g_keycode_to_key_normal[keycode_normal(2, 4)] = Key::F;
g_keycode_to_key_normal[keycode_normal(2, 5)] = Key::G;
g_keycode_to_key_normal[keycode_normal(2, 6)] = Key::H;
g_keycode_to_key_normal[keycode_normal(2, 7)] = Key::J;
g_keycode_to_key_normal[keycode_normal(2, 8)] = Key::K;
g_keycode_to_key_normal[keycode_normal(2, 9)] = Key::L;
g_keycode_to_key_normal[keycode_normal(2, 10)] = Key::O_Umlaut;
g_keycode_to_key_normal[keycode_normal(2, 11)] = Key::A_Umlaut;
g_keycode_to_key_normal[keycode_normal(2, 12)] = Key::SingleQuote;
g_keycode_to_key_normal[keycode_normal(2, 13)] = Key::Enter;
g_keycode_to_key_normal[keycode_normal(3, 0)] = Key::LeftShift;
g_keycode_to_key_normal[keycode_normal(3, 1)] = Key::LessThan;
g_keycode_to_key_normal[keycode_normal(3, 2)] = Key::Z;
g_keycode_to_key_normal[keycode_normal(3, 3)] = Key::X;
g_keycode_to_key_normal[keycode_normal(3, 4)] = Key::C;
g_keycode_to_key_normal[keycode_normal(3, 5)] = Key::V;
g_keycode_to_key_normal[keycode_normal(3, 6)] = Key::B;
g_keycode_to_key_normal[keycode_normal(3, 7)] = Key::N;
g_keycode_to_key_normal[keycode_normal(3, 8)] = Key::M;
g_keycode_to_key_normal[keycode_normal(3, 9)] = Key::Comma;
g_keycode_to_key_normal[keycode_normal(3, 10)] = Key::Period;
g_keycode_to_key_normal[keycode_normal(3, 11)] = Key::Hyphen;
g_keycode_to_key_normal[keycode_normal(3, 12)] = Key::RightShift;
g_keycode_to_key_normal[keycode_normal(4, 0)] = Key::LeftCtrl;
g_keycode_to_key_normal[keycode_normal(4, 1)] = Key::Super;
g_keycode_to_key_normal[keycode_normal(4, 2)] = Key::LeftAlt;
g_keycode_to_key_normal[keycode_normal(4, 3)] = Key::Space;
g_keycode_to_key_normal[keycode_normal(4, 4)] = Key::RightAlt;
g_keycode_to_key_normal[keycode_normal(4, 5)] = Key::RightCtrl;
g_keycode_to_key_normal[keycode_numpad(0, 0)] = Key::NumLock;
g_keycode_to_key_normal[keycode_numpad(0, 1)] = Key::NumpadDivide;
g_keycode_to_key_normal[keycode_numpad(0, 2)] = Key::NumpadMultiply;
g_keycode_to_key_normal[keycode_numpad(0, 3)] = Key::NumpadMinus;
g_keycode_to_key_normal[keycode_numpad(1, 0)] = Key::Numpad7;
g_keycode_to_key_normal[keycode_numpad(1, 1)] = Key::Numpad8;
g_keycode_to_key_normal[keycode_numpad(1, 2)] = Key::Numpad9;
g_keycode_to_key_normal[keycode_numpad(1, 3)] = Key::NumpadPlus;
g_keycode_to_key_normal[keycode_numpad(2, 0)] = Key::Numpad4;
g_keycode_to_key_normal[keycode_numpad(2, 1)] = Key::Numpad5;
g_keycode_to_key_normal[keycode_numpad(2, 2)] = Key::Numpad6;
g_keycode_to_key_normal[keycode_numpad(3, 0)] = Key::Numpad1;
g_keycode_to_key_normal[keycode_numpad(3, 1)] = Key::Numpad2;
g_keycode_to_key_normal[keycode_numpad(3, 2)] = Key::Numpad3;
g_keycode_to_key_normal[keycode_numpad(3, 3)] = Key::NumpadEnter;
g_keycode_to_key_normal[keycode_numpad(4, 0)] = Key::Numpad0;
g_keycode_to_key_normal[keycode_numpad(4, 1)] = Key::NumpadDecimal;
g_keycode_to_key_normal[keycode_function( 0)] = Key::Escape;
g_keycode_to_key_normal[keycode_function( 1)] = Key::F1;
g_keycode_to_key_normal[keycode_function( 2)] = Key::F2;
g_keycode_to_key_normal[keycode_function( 3)] = Key::F3;
g_keycode_to_key_normal[keycode_function( 4)] = Key::F4;
g_keycode_to_key_normal[keycode_function( 5)] = Key::F5;
g_keycode_to_key_normal[keycode_function( 6)] = Key::F6;
g_keycode_to_key_normal[keycode_function( 7)] = Key::F7;
g_keycode_to_key_normal[keycode_function( 8)] = Key::F8;
g_keycode_to_key_normal[keycode_function( 9)] = Key::F9;
g_keycode_to_key_normal[keycode_function(10)] = Key::F10;
g_keycode_to_key_normal[keycode_function(11)] = Key::F11;
g_keycode_to_key_normal[keycode_function(12)] = Key::F12;
g_keycode_to_key_normal[keycode_function(13)] = Key::Insert;
g_keycode_to_key_normal[keycode_function(14)] = Key::PrintScreen;
g_keycode_to_key_normal[keycode_function(15)] = Key::Delete;
g_keycode_to_key_normal[keycode_function(16)] = Key::Home;
g_keycode_to_key_normal[keycode_function(17)] = Key::End;
g_keycode_to_key_normal[keycode_function(18)] = Key::PageUp;
g_keycode_to_key_normal[keycode_function(19)] = Key::PageDown;
g_keycode_to_key_normal[keycode_function(20)] = Key::ScrollLock;
// Arrow keys
g_keycode_to_key_normal[keycode_normal(5, 0)] = Key::ArrowUp;
g_keycode_to_key_normal[keycode_normal(5, 1)] = Key::ArrowLeft;
g_keycode_to_key_normal[keycode_normal(5, 2)] = Key::ArrowDown;
g_keycode_to_key_normal[keycode_normal(5, 3)] = Key::ArrowRight;
}
static void initialize_fi_shift()
{
g_keycode_to_key_shift[keycode_normal(0, 0)] = Key::Half;
g_keycode_to_key_shift[keycode_normal(0, 1)] = Key::ExclamationMark;
g_keycode_to_key_shift[keycode_normal(0, 2)] = Key::DoubleQuote;
g_keycode_to_key_shift[keycode_normal(0, 3)] = Key::Hashtag;
g_keycode_to_key_shift[keycode_normal(0, 4)] = Key::Currency;
g_keycode_to_key_shift[keycode_normal(0, 5)] = Key::Percent;
g_keycode_to_key_shift[keycode_normal(0, 6)] = Key::Ampersand;
g_keycode_to_key_shift[keycode_normal(0, 7)] = Key::Slash;
g_keycode_to_key_shift[keycode_normal(0, 8)] = Key::OpenParenthesis;
g_keycode_to_key_shift[keycode_normal(0, 9)] = Key::CloseParenthesis;
g_keycode_to_key_shift[keycode_normal(0, 10)] = Key::Equals;
g_keycode_to_key_shift[keycode_normal(0, 11)] = Key::QuestionMark;
g_keycode_to_key_shift[keycode_normal(0, 12)] = Key::BackTick;
g_keycode_to_key_shift[keycode_normal(0, 13)] = Key::Backspace;
g_keycode_to_key_shift[keycode_normal(1, 0)] = Key::Tab;
g_keycode_to_key_shift[keycode_normal(1, 1)] = Key::Q;
g_keycode_to_key_shift[keycode_normal(1, 2)] = Key::W;
g_keycode_to_key_shift[keycode_normal(1, 3)] = Key::E;
g_keycode_to_key_shift[keycode_normal(1, 4)] = Key::R;
g_keycode_to_key_shift[keycode_normal(1, 5)] = Key::T;
g_keycode_to_key_shift[keycode_normal(1, 6)] = Key::Y;
g_keycode_to_key_shift[keycode_normal(1, 7)] = Key::U;
g_keycode_to_key_shift[keycode_normal(1, 8)] = Key::I;
g_keycode_to_key_shift[keycode_normal(1, 9)] = Key::O;
g_keycode_to_key_shift[keycode_normal(1, 10)] = Key::P;
g_keycode_to_key_shift[keycode_normal(1, 11)] = Key::A_Ring;
g_keycode_to_key_shift[keycode_normal(1, 12)] = Key::Caret;
g_keycode_to_key_shift[keycode_normal(2, 0)] = Key::CapsLock;
g_keycode_to_key_shift[keycode_normal(2, 1)] = Key::A;
g_keycode_to_key_shift[keycode_normal(2, 2)] = Key::S;
g_keycode_to_key_shift[keycode_normal(2, 3)] = Key::D;
g_keycode_to_key_shift[keycode_normal(2, 4)] = Key::F;
g_keycode_to_key_shift[keycode_normal(2, 5)] = Key::G;
g_keycode_to_key_shift[keycode_normal(2, 6)] = Key::H;
g_keycode_to_key_shift[keycode_normal(2, 7)] = Key::J;
g_keycode_to_key_shift[keycode_normal(2, 8)] = Key::K;
g_keycode_to_key_shift[keycode_normal(2, 9)] = Key::L;
g_keycode_to_key_shift[keycode_normal(2, 10)] = Key::O_Umlaut;
g_keycode_to_key_shift[keycode_normal(2, 11)] = Key::A_Umlaut;
g_keycode_to_key_shift[keycode_normal(2, 12)] = Key::Asterix;
g_keycode_to_key_shift[keycode_normal(2, 13)] = Key::Enter;
g_keycode_to_key_shift[keycode_normal(3, 0)] = Key::LeftShift;
g_keycode_to_key_shift[keycode_normal(3, 1)] = Key::GreaterThan;
g_keycode_to_key_shift[keycode_normal(3, 2)] = Key::Z;
g_keycode_to_key_shift[keycode_normal(3, 3)] = Key::X;
g_keycode_to_key_shift[keycode_normal(3, 4)] = Key::C;
g_keycode_to_key_shift[keycode_normal(3, 5)] = Key::V;
g_keycode_to_key_shift[keycode_normal(3, 6)] = Key::B;
g_keycode_to_key_shift[keycode_normal(3, 7)] = Key::N;
g_keycode_to_key_shift[keycode_normal(3, 8)] = Key::M;
g_keycode_to_key_shift[keycode_normal(3, 9)] = Key::Semicolon;
g_keycode_to_key_shift[keycode_normal(3, 10)] = Key::Colon;
g_keycode_to_key_shift[keycode_normal(3, 11)] = Key::Underscore;
g_keycode_to_key_shift[keycode_normal(3, 12)] = Key::RightShift;
g_keycode_to_key_shift[keycode_normal(4, 0)] = Key::LeftCtrl;
g_keycode_to_key_shift[keycode_normal(4, 1)] = Key::Super;
g_keycode_to_key_shift[keycode_normal(4, 2)] = Key::LeftAlt;
g_keycode_to_key_shift[keycode_normal(4, 3)] = Key::Space;
g_keycode_to_key_shift[keycode_normal(4, 4)] = Key::RightAlt;
g_keycode_to_key_shift[keycode_normal(4, 5)] = Key::RightCtrl;
g_keycode_to_key_shift[keycode_numpad(0, 0)] = Key::NumLock;
g_keycode_to_key_shift[keycode_numpad(0, 1)] = Key::NumpadDivide;
g_keycode_to_key_shift[keycode_numpad(0, 2)] = Key::NumpadMultiply;
g_keycode_to_key_shift[keycode_numpad(0, 3)] = Key::NumpadMinus;
g_keycode_to_key_shift[keycode_numpad(1, 0)] = Key::Numpad7;
g_keycode_to_key_shift[keycode_numpad(1, 1)] = Key::Numpad8;
g_keycode_to_key_shift[keycode_numpad(1, 2)] = Key::Numpad9;
g_keycode_to_key_shift[keycode_numpad(1, 3)] = Key::NumpadPlus;
g_keycode_to_key_shift[keycode_numpad(2, 0)] = Key::Numpad4;
g_keycode_to_key_shift[keycode_numpad(2, 1)] = Key::Numpad5;
g_keycode_to_key_shift[keycode_numpad(2, 2)] = Key::Numpad6;
g_keycode_to_key_shift[keycode_numpad(3, 0)] = Key::Numpad1;
g_keycode_to_key_shift[keycode_numpad(3, 1)] = Key::Numpad2;
g_keycode_to_key_shift[keycode_numpad(3, 2)] = Key::Numpad3;
g_keycode_to_key_shift[keycode_numpad(3, 3)] = Key::NumpadEnter;
g_keycode_to_key_shift[keycode_numpad(4, 0)] = Key::Numpad0;
g_keycode_to_key_shift[keycode_numpad(4, 1)] = Key::NumpadDecimal;
g_keycode_to_key_shift[keycode_function( 0)] = Key::Escape;
g_keycode_to_key_shift[keycode_function( 1)] = Key::F1;
g_keycode_to_key_shift[keycode_function( 2)] = Key::F2;
g_keycode_to_key_shift[keycode_function( 3)] = Key::F3;
g_keycode_to_key_shift[keycode_function( 4)] = Key::F4;
g_keycode_to_key_shift[keycode_function( 5)] = Key::F5;
g_keycode_to_key_shift[keycode_function( 6)] = Key::F6;
g_keycode_to_key_shift[keycode_function( 7)] = Key::F7;
g_keycode_to_key_shift[keycode_function( 8)] = Key::F8;
g_keycode_to_key_shift[keycode_function( 9)] = Key::F9;
g_keycode_to_key_shift[keycode_function(10)] = Key::F10;
g_keycode_to_key_shift[keycode_function(11)] = Key::F11;
g_keycode_to_key_shift[keycode_function(12)] = Key::F12;
g_keycode_to_key_shift[keycode_function(13)] = Key::Insert;
g_keycode_to_key_shift[keycode_function(14)] = Key::PrintScreen;
g_keycode_to_key_shift[keycode_function(15)] = Key::Delete;
g_keycode_to_key_shift[keycode_function(16)] = Key::Home;
g_keycode_to_key_shift[keycode_function(17)] = Key::End;
g_keycode_to_key_shift[keycode_function(18)] = Key::PageUp;
g_keycode_to_key_shift[keycode_function(19)] = Key::PageDown;
g_keycode_to_key_shift[keycode_function(20)] = Key::ScrollLock;
// Arrow keys
g_keycode_to_key_shift[keycode_normal(5, 0)] = Key::ArrowUp;
g_keycode_to_key_shift[keycode_normal(5, 1)] = Key::ArrowLeft;
g_keycode_to_key_shift[keycode_normal(5, 2)] = Key::ArrowDown;
g_keycode_to_key_shift[keycode_normal(5, 3)] = Key::ArrowRight;
}
static void initialize_fi_altgr()
{
g_keycode_to_key_altgr[keycode_normal(0, 0)] = Key::Section;
g_keycode_to_key_altgr[keycode_normal(0, 1)] = Key::None;
g_keycode_to_key_altgr[keycode_normal(0, 2)] = Key::AtSign;
g_keycode_to_key_altgr[keycode_normal(0, 3)] = Key::Pound;
g_keycode_to_key_altgr[keycode_normal(0, 4)] = Key::Dollar;
g_keycode_to_key_altgr[keycode_normal(0, 5)] = Key::None;
g_keycode_to_key_altgr[keycode_normal(0, 6)] = Key::None;
g_keycode_to_key_altgr[keycode_normal(0, 7)] = Key::OpenCurlyBracket;
g_keycode_to_key_altgr[keycode_normal(0, 8)] = Key::OpenSquareBracket;
g_keycode_to_key_altgr[keycode_normal(0, 9)] = Key::CloseSquareBracket;
g_keycode_to_key_altgr[keycode_normal(0, 10)] = Key::CloseCurlyBracket;
g_keycode_to_key_altgr[keycode_normal(0, 11)] = Key::BackSlash;
g_keycode_to_key_altgr[keycode_normal(0, 12)] = Key::Cedilla;
g_keycode_to_key_altgr[keycode_normal(0, 13)] = Key::Backspace;
g_keycode_to_key_altgr[keycode_normal(1, 0)] = Key::Tab;
g_keycode_to_key_altgr[keycode_normal(1, 1)] = Key::Q;
g_keycode_to_key_altgr[keycode_normal(1, 2)] = Key::W;
g_keycode_to_key_altgr[keycode_normal(1, 3)] = Key::Euro;
g_keycode_to_key_altgr[keycode_normal(1, 4)] = Key::R;
g_keycode_to_key_altgr[keycode_normal(1, 5)] = Key::T;
g_keycode_to_key_altgr[keycode_normal(1, 6)] = Key::Y;
g_keycode_to_key_altgr[keycode_normal(1, 7)] = Key::U;
g_keycode_to_key_altgr[keycode_normal(1, 8)] = Key::I;
g_keycode_to_key_altgr[keycode_normal(1, 9)] = Key::O;
g_keycode_to_key_altgr[keycode_normal(1, 10)] = Key::P;
g_keycode_to_key_altgr[keycode_normal(1, 11)] = Key::A_Ring;
g_keycode_to_key_altgr[keycode_normal(1, 12)] = Key::Tilde;
g_keycode_to_key_altgr[keycode_normal(2, 0)] = Key::CapsLock;
g_keycode_to_key_altgr[keycode_normal(2, 1)] = Key::A;
g_keycode_to_key_altgr[keycode_normal(2, 2)] = Key::S;
g_keycode_to_key_altgr[keycode_normal(2, 3)] = Key::D;
g_keycode_to_key_altgr[keycode_normal(2, 4)] = Key::F;
g_keycode_to_key_altgr[keycode_normal(2, 5)] = Key::G;
g_keycode_to_key_altgr[keycode_normal(2, 6)] = Key::H;
g_keycode_to_key_altgr[keycode_normal(2, 7)] = Key::J;
g_keycode_to_key_altgr[keycode_normal(2, 8)] = Key::K;
g_keycode_to_key_altgr[keycode_normal(2, 9)] = Key::L;
g_keycode_to_key_altgr[keycode_normal(2, 10)] = Key::O_Umlaut;
g_keycode_to_key_altgr[keycode_normal(2, 11)] = Key::A_Umlaut;
g_keycode_to_key_altgr[keycode_normal(2, 12)] = Key::None;
g_keycode_to_key_altgr[keycode_normal(2, 13)] = Key::Enter;
g_keycode_to_key_altgr[keycode_normal(3, 0)] = Key::LeftShift;
g_keycode_to_key_altgr[keycode_normal(3, 1)] = Key::Pipe;
g_keycode_to_key_altgr[keycode_normal(3, 2)] = Key::Z;
g_keycode_to_key_altgr[keycode_normal(3, 3)] = Key::X;
g_keycode_to_key_altgr[keycode_normal(3, 4)] = Key::C;
g_keycode_to_key_altgr[keycode_normal(3, 5)] = Key::V;
g_keycode_to_key_altgr[keycode_normal(3, 6)] = Key::B;
g_keycode_to_key_altgr[keycode_normal(3, 7)] = Key::N;
g_keycode_to_key_altgr[keycode_normal(3, 8)] = Key::M;
g_keycode_to_key_altgr[keycode_normal(3, 9)] = Key::None;
g_keycode_to_key_altgr[keycode_normal(3, 10)] = Key::None;
g_keycode_to_key_altgr[keycode_normal(3, 11)] = Key::None;
g_keycode_to_key_altgr[keycode_normal(3, 12)] = Key::RightShift;
g_keycode_to_key_altgr[keycode_normal(4, 0)] = Key::LeftCtrl;
g_keycode_to_key_altgr[keycode_normal(4, 1)] = Key::Super;
g_keycode_to_key_altgr[keycode_normal(4, 2)] = Key::LeftAlt;
g_keycode_to_key_altgr[keycode_normal(4, 3)] = Key::Space;
g_keycode_to_key_altgr[keycode_normal(4, 4)] = Key::RightAlt;
g_keycode_to_key_altgr[keycode_normal(4, 5)] = Key::RightCtrl;
g_keycode_to_key_altgr[keycode_numpad(0, 0)] = Key::NumLock;
g_keycode_to_key_altgr[keycode_numpad(0, 1)] = Key::NumpadDivide;
g_keycode_to_key_altgr[keycode_numpad(0, 2)] = Key::NumpadMultiply;
g_keycode_to_key_altgr[keycode_numpad(0, 3)] = Key::NumpadMinus;
g_keycode_to_key_altgr[keycode_numpad(1, 0)] = Key::Numpad7;
g_keycode_to_key_altgr[keycode_numpad(1, 1)] = Key::Numpad8;
g_keycode_to_key_altgr[keycode_numpad(1, 2)] = Key::Numpad9;
g_keycode_to_key_altgr[keycode_numpad(1, 3)] = Key::NumpadPlus;
g_keycode_to_key_altgr[keycode_numpad(2, 0)] = Key::Numpad4;
g_keycode_to_key_altgr[keycode_numpad(2, 1)] = Key::Numpad5;
g_keycode_to_key_altgr[keycode_numpad(2, 2)] = Key::Numpad6;
g_keycode_to_key_altgr[keycode_numpad(3, 0)] = Key::Numpad1;
g_keycode_to_key_altgr[keycode_numpad(3, 1)] = Key::Numpad2;
g_keycode_to_key_altgr[keycode_numpad(3, 2)] = Key::Numpad3;
g_keycode_to_key_altgr[keycode_numpad(3, 3)] = Key::NumpadEnter;
g_keycode_to_key_altgr[keycode_numpad(4, 0)] = Key::Numpad0;
g_keycode_to_key_altgr[keycode_numpad(4, 1)] = Key::NumpadDecimal;
g_keycode_to_key_altgr[keycode_function( 0)] = Key::Escape;
g_keycode_to_key_altgr[keycode_function( 1)] = Key::F1;
g_keycode_to_key_altgr[keycode_function( 2)] = Key::F2;
g_keycode_to_key_altgr[keycode_function( 3)] = Key::F3;
g_keycode_to_key_altgr[keycode_function( 4)] = Key::F4;
g_keycode_to_key_altgr[keycode_function( 5)] = Key::F5;
g_keycode_to_key_altgr[keycode_function( 6)] = Key::F6;
g_keycode_to_key_altgr[keycode_function( 7)] = Key::F7;
g_keycode_to_key_altgr[keycode_function( 8)] = Key::F8;
g_keycode_to_key_altgr[keycode_function( 9)] = Key::F9;
g_keycode_to_key_altgr[keycode_function(10)] = Key::F10;
g_keycode_to_key_altgr[keycode_function(11)] = Key::F11;
g_keycode_to_key_altgr[keycode_function(12)] = Key::F12;
g_keycode_to_key_altgr[keycode_function(13)] = Key::Insert;
g_keycode_to_key_altgr[keycode_function(14)] = Key::PrintScreen;
g_keycode_to_key_altgr[keycode_function(15)] = Key::Delete;
g_keycode_to_key_altgr[keycode_function(16)] = Key::Home;
g_keycode_to_key_altgr[keycode_function(17)] = Key::End;
g_keycode_to_key_altgr[keycode_function(18)] = Key::PageUp;
g_keycode_to_key_altgr[keycode_function(19)] = Key::PageDown;
g_keycode_to_key_altgr[keycode_function(20)] = Key::ScrollLock;
// Arrow keys
g_keycode_to_key_altgr[keycode_normal(5, 0)] = Key::ArrowUp;
g_keycode_to_key_altgr[keycode_normal(5, 1)] = Key::ArrowLeft;
g_keycode_to_key_altgr[keycode_normal(5, 2)] = Key::ArrowDown;
g_keycode_to_key_altgr[keycode_normal(5, 3)] = Key::ArrowRight;
}
}

View File

@ -25,9 +25,24 @@ namespace Kernel::Input
void PS2Keyboard::send_initialize()
{
constexpr uint8_t wanted_scancode_set = 3;
append_command_queue(Command::SET_LEDS, 0x00, 0);
append_command_queue(Command::SCANCODE, PS2::KBScancode::SET_SCANCODE_SET2, 0);
append_command_queue(PS2::DeviceCommand::ENABLE_SCANNING, 0);
append_command_queue(Command::CONFIG_SCANCODE_SET, wanted_scancode_set, 0);
append_command_queue(Command::CONFIG_SCANCODE_SET, 0, 1);
}
void PS2Keyboard::command_timedout(uint8_t* command_data, uint8_t command_size)
{
if (command_size == 0)
return;
if (command_data[0] == Command::CONFIG_SCANCODE_SET && m_scancode_set >= 0xFE)
{
dwarnln("Could not detect scancode set, assuming 1");
m_scancode_set = 1;
m_keymap.initialize(m_scancode_set);
append_command_queue(PS2::DeviceCommand::ENABLE_SCANNING, 0);
}
}
void PS2Keyboard::handle_byte(uint8_t byte)
@ -38,69 +53,93 @@ namespace Kernel::Input
return;
}
if (m_scancode_set == 0xFF)
{
append_command_queue(Command::CONFIG_SCANCODE_SET, 0, 1);
m_scancode_set = 0xFE;
return;
}
if (m_scancode_set == 0xFE)
{
if (1 <= byte && byte <= 3)
{
m_scancode_set = byte;
dprintln("Using scancode set {}", m_scancode_set);
}
else
{
dwarnln("Could not detect scancode set, assuming 1");
m_scancode_set = 1;
}
m_keymap.initialize(m_scancode_set);
append_command_queue(PS2::DeviceCommand::ENABLE_SCANNING, 0);
return;
}
if (m_byte_index >= 3)
{
dwarnln("PS/2 corrupted key packet");
m_byte_index = 0;
return;
}
m_byte_buffer[m_byte_index++] = byte;
if (byte == 0xE0 || byte == 0xF0)
if (byte == 0xE0)
return;
if ((m_scancode_set == 2 || m_scancode_set == 3) && byte == 0xF0)
return;
uint32_t scancode = 0;
bool extended = false;
bool released = false;
for (uint8_t i = 0; i < m_byte_index; i++)
uint8_t index = 0;
// in all scancode sets, extended scancode is indicated by byte 0xE0
if (index < m_byte_index && m_byte_buffer[index] == 0xE0)
{
if (m_byte_buffer[i] == 0xE0)
extended = true;
else if (m_byte_buffer[i] == 0xF0)
released = true;
else
scancode = (scancode << 8) | m_byte_buffer[i];
extended = true;
index++;
}
// in scancode set 1, released key is indicated by bit 7 set
if (m_scancode_set == 1 && (m_byte_buffer[index] & 0x80))
{
released = true;
m_byte_buffer[index] &= 0x7F;
}
// in scancode set 2 and 3, released key is indicated by byte 0xF0
if ((m_scancode_set == 2 || m_scancode_set == 3) && m_byte_buffer[index] == 0xF0)
{
released = true;
index++;
}
if (extended)
scancode |= 0x80000000;
bool corrupted = (index + 1 != m_byte_index);
m_byte_index = 0;
Key key = m_keymap.key_for_scancode_and_modifiers(scancode, m_modifiers);
if (key == Key::None)
return;
if (key == Input::Key::Invalid)
if (corrupted)
{
dprintln("unknown key for scancode {2H} {}", scancode & 0x7FFFFFFF, extended ? 'E' : ' ');
dwarnln("PS/2 corrupted key packet");
return;
}
uint8_t modifier_mask = 0;
uint8_t toggle_mask = 0;
switch (key)
auto keycode = m_keymap.get_keycode(m_byte_buffer[index], extended);
if (!keycode.has_value())
return;
uint16_t modifier_mask = 0;
uint16_t toggle_mask = 0;
switch (keycode.value())
{
case Input::Key::LeftShift:
case Input::Key::RightShift:
modifier_mask = (uint8_t)Input::KeyEvent::Modifier::Shift;
break;
case Input::Key::LeftCtrl:
case Input::Key::RightCtrl:
modifier_mask = (uint8_t)Input::KeyEvent::Modifier::Ctrl;
break;
case Input::Key::Alt:
modifier_mask = (uint8_t)Input::KeyEvent::Modifier::Alt;
break;
case Input::Key::AltGr:
modifier_mask = (uint8_t)Input::KeyEvent::Modifier::AltGr;
break;;
case Input::Key::ScrollLock:
toggle_mask = (uint8_t)Input::KeyEvent::Modifier::ScrollLock;
break;
case Input::Key::NumLock:
toggle_mask = (uint8_t)Input::KeyEvent::Modifier::NumLock;
break;
case Input::Key::CapsLock:
toggle_mask = (uint8_t)Input::KeyEvent::Modifier::CapsLock;
break;
default:
break;
case ModifierKeycode::LShift: modifier_mask = KeyEvent::Modifier::LShift; break;
case ModifierKeycode::RShift: modifier_mask = KeyEvent::Modifier::RShift; break;
case ModifierKeycode::LCtrl: modifier_mask = KeyEvent::Modifier::LCtrl; break;
case ModifierKeycode::RCtrl: modifier_mask = KeyEvent::Modifier::RCtrl; break;
case ModifierKeycode::LAlt: modifier_mask = KeyEvent::Modifier::LAlt; break;
case ModifierKeycode::RAlt: modifier_mask = KeyEvent::Modifier::RAlt; break;
case ModifierKeycode::ScrollLock: toggle_mask = KeyEvent::Modifier::ScrollLock; break;
case ModifierKeycode::NumLock: toggle_mask = KeyEvent::Modifier::NumLock; break;
case ModifierKeycode::CapsLock: toggle_mask = KeyEvent::Modifier::CapsLock; break;
}
if (modifier_mask)
@ -111,15 +150,15 @@ namespace Kernel::Input
m_modifiers |= modifier_mask;
}
if (toggle_mask && !released)
if (toggle_mask)
{
m_modifiers ^= toggle_mask;
update_leds();
}
Input::KeyEvent event;
event.modifier = m_modifiers | (released ? (uint8_t)Input::KeyEvent::Modifier::Released : 0);
event.key = key;
KeyEvent event;
event.modifier = m_modifiers | (released ? 0 : KeyEvent::Modifier::Pressed);
event.keycode = keycode.value();
if (m_event_queue.full())
{
@ -134,11 +173,11 @@ namespace Kernel::Input
void PS2Keyboard::update_leds()
{
uint8_t new_leds = 0;
if (m_modifiers & (uint8_t)Input::KeyEvent::Modifier::ScrollLock)
if (m_modifiers & +Input::KeyEvent::Modifier::ScrollLock)
new_leds |= PS2::KBLeds::SCROLL_LOCK;
if (m_modifiers & (uint8_t)Input::KeyEvent::Modifier::NumLock)
if (m_modifiers & +Input::KeyEvent::Modifier::NumLock)
new_leds |= PS2::KBLeds::NUM_LOCK;
if (m_modifiers & (uint8_t)Input::KeyEvent::Modifier::CapsLock)
if (m_modifiers & +Input::KeyEvent::Modifier::CapsLock)
new_leds |= PS2::KBLeds::CAPS_LOCK;
append_command_queue(Command::SET_LEDS, new_leds, 0);
}

View File

@ -1,360 +1,361 @@
#include <kernel/Input/KeyEvent.h>
#include <kernel/Input/PS2/Keymap.h>
namespace Kernel::Input
{
PS2Keymap::PS2Keymap()
void PS2Keymap::initialize(uint8_t scancode_set)
{
MUST(m_normal_keymap.resize(0xFF, Key::Invalid));
m_normal_keymap[0x01] = Key::F9;
m_normal_keymap[0x03] = Key::F5;
m_normal_keymap[0x04] = Key::F3;
m_normal_keymap[0x05] = Key::F1;
m_normal_keymap[0x06] = Key::F2;
m_normal_keymap[0x07] = Key::F11;
m_normal_keymap[0x09] = Key::F10;
m_normal_keymap[0x0A] = Key::F8;
m_normal_keymap[0x0B] = Key::F6;
m_normal_keymap[0x0C] = Key::F4;
m_normal_keymap[0x0D] = Key::Tab;
m_normal_keymap[0x0E] = Key::Section;
m_normal_keymap[0x11] = Key::Alt;
m_normal_keymap[0x12] = Key::LeftShift;
m_normal_keymap[0x14] = Key::LeftCtrl;
m_normal_keymap[0x15] = Key::Q;
m_normal_keymap[0x16] = Key::_1;
m_normal_keymap[0x1A] = Key::Z;
m_normal_keymap[0x1B] = Key::S;
m_normal_keymap[0x1C] = Key::A;
m_normal_keymap[0x1D] = Key::W;
m_normal_keymap[0x1E] = Key::_2;
m_normal_keymap[0x21] = Key::C;
m_normal_keymap[0x22] = Key::X;
m_normal_keymap[0x23] = Key::D;
m_normal_keymap[0x24] = Key::E;
m_normal_keymap[0x25] = Key::_4;
m_normal_keymap[0x26] = Key::_3;
m_normal_keymap[0x29] = Key::Space;
m_normal_keymap[0x2A] = Key::V;
m_normal_keymap[0x2B] = Key::F;
m_normal_keymap[0x2C] = Key::T;
m_normal_keymap[0x2D] = Key::R;
m_normal_keymap[0x2E] = Key::_5;
m_normal_keymap[0x31] = Key::N;
m_normal_keymap[0x32] = Key::B;
m_normal_keymap[0x33] = Key::H;
m_normal_keymap[0x34] = Key::G;
m_normal_keymap[0x35] = Key::Y;
m_normal_keymap[0x36] = Key::_6;
m_normal_keymap[0x3A] = Key::M;
m_normal_keymap[0x3B] = Key::J;
m_normal_keymap[0x3C] = Key::U;
m_normal_keymap[0x3D] = Key::_7;
m_normal_keymap[0x3E] = Key::_8;
m_normal_keymap[0x41] = Key::Comma;
m_normal_keymap[0x42] = Key::K;
m_normal_keymap[0x43] = Key::I;
m_normal_keymap[0x44] = Key::O;
m_normal_keymap[0x45] = Key::_0;
m_normal_keymap[0x46] = Key::_9;
m_normal_keymap[0x49] = Key::Period;
m_normal_keymap[0x4A] = Key::Hyphen;
m_normal_keymap[0x4B] = Key::L;
m_normal_keymap[0x4C] = Key::O_Umlaut;
m_normal_keymap[0x4D] = Key::P;
m_normal_keymap[0x4E] = Key::Plus;
m_normal_keymap[0x52] = Key::A_Umlaut;
m_normal_keymap[0x54] = Key::A_Ring;
m_normal_keymap[0x55] = Key::Acute;
m_normal_keymap[0x58] = Key::CapsLock;
m_normal_keymap[0x59] = Key::RightShift;
m_normal_keymap[0x59] = Key::RightShift;
m_normal_keymap[0x5A] = Key::Enter;
m_normal_keymap[0x5B] = Key::TwoDots;
m_normal_keymap[0x5D] = Key::SingleQuote;
m_normal_keymap[0x61] = Key::LessThan;
m_normal_keymap[0x66] = Key::Backspace;
m_normal_keymap[0x69] = Key::Numpad1;
m_normal_keymap[0x6B] = Key::Numpad4;
m_normal_keymap[0x6C] = Key::Numpad7;
m_normal_keymap[0x70] = Key::Numpad0;
m_normal_keymap[0x71] = Key::NumpadDecimal;
m_normal_keymap[0x72] = Key::Numpad2;
m_normal_keymap[0x73] = Key::Numpad5;
m_normal_keymap[0x74] = Key::Numpad6;
m_normal_keymap[0x75] = Key::Numpad8;
m_normal_keymap[0x76] = Key::Escape;
m_normal_keymap[0x77] = Key::NumLock;
m_normal_keymap[0x78] = Key::F11;
m_normal_keymap[0x79] = Key::NumpadPlus;
m_normal_keymap[0x7A] = Key::Numpad3;
m_normal_keymap[0x7B] = Key::NumpadMinus;
m_normal_keymap[0x7C] = Key::NumpadMultiply;
m_normal_keymap[0x7D] = Key::Numpad9;
m_normal_keymap[0x83] = Key::F7;
MUST(m_shift_keymap.resize(0xFF, Key::Invalid));
m_shift_keymap[0x01] = Key::F9;
m_shift_keymap[0x03] = Key::F5;
m_shift_keymap[0x04] = Key::F3;
m_shift_keymap[0x05] = Key::F1;
m_shift_keymap[0x06] = Key::F2;
m_shift_keymap[0x07] = Key::F11;
m_shift_keymap[0x09] = Key::F10;
m_shift_keymap[0x0A] = Key::F8;
m_shift_keymap[0x0B] = Key::F6;
m_shift_keymap[0x0C] = Key::F4;
m_shift_keymap[0x0D] = Key::Tab;
m_shift_keymap[0x0E] = Key::Half;
m_shift_keymap[0x11] = Key::Alt;
m_shift_keymap[0x12] = Key::LeftShift;
m_shift_keymap[0x14] = Key::LeftCtrl;
m_shift_keymap[0x15] = Key::Q;
m_shift_keymap[0x16] = Key::ExclamationMark;
m_shift_keymap[0x1A] = Key::Z;
m_shift_keymap[0x1B] = Key::S;
m_shift_keymap[0x1C] = Key::A;
m_shift_keymap[0x1D] = Key::W;
m_shift_keymap[0x1E] = Key::DoubleQuote;
m_shift_keymap[0x21] = Key::C;
m_shift_keymap[0x22] = Key::X;
m_shift_keymap[0x23] = Key::D;
m_shift_keymap[0x24] = Key::E;
m_shift_keymap[0x25] = Key::Currency;
m_shift_keymap[0x26] = Key::Hashtag;
m_shift_keymap[0x29] = Key::Space;
m_shift_keymap[0x2A] = Key::V;
m_shift_keymap[0x2B] = Key::F;
m_shift_keymap[0x2C] = Key::T;
m_shift_keymap[0x2D] = Key::R;
m_shift_keymap[0x2E] = Key::Percent;
m_shift_keymap[0x31] = Key::N;
m_shift_keymap[0x32] = Key::B;
m_shift_keymap[0x33] = Key::H;
m_shift_keymap[0x34] = Key::G;
m_shift_keymap[0x35] = Key::Y;
m_shift_keymap[0x36] = Key::Ampersand;
m_shift_keymap[0x3A] = Key::M;
m_shift_keymap[0x3B] = Key::J;
m_shift_keymap[0x3C] = Key::U;
m_shift_keymap[0x3D] = Key::Slash;
m_shift_keymap[0x3E] = Key::OpenBracet;
m_shift_keymap[0x41] = Key::Semicolon;
m_shift_keymap[0x42] = Key::K;
m_shift_keymap[0x43] = Key::I;
m_shift_keymap[0x44] = Key::O;
m_shift_keymap[0x45] = Key::Equals;
m_shift_keymap[0x46] = Key::CloseBracet;
m_shift_keymap[0x49] = Key::Colon;
m_shift_keymap[0x4A] = Key::Underscore;
m_shift_keymap[0x4B] = Key::L;
m_shift_keymap[0x4C] = Key::O_Umlaut;
m_shift_keymap[0x4D] = Key::P;
m_shift_keymap[0x4E] = Key::QuestionMark;
m_shift_keymap[0x52] = Key::A_Umlaut;
m_shift_keymap[0x54] = Key::A_Ring;
m_shift_keymap[0x55] = Key::BackTick;
m_shift_keymap[0x58] = Key::CapsLock;
m_shift_keymap[0x59] = Key::RightShift;
m_shift_keymap[0x59] = Key::RightShift;
m_shift_keymap[0x5A] = Key::Enter;
m_shift_keymap[0x5B] = Key::Caret;
m_shift_keymap[0x5D] = Key::Asterix;
m_shift_keymap[0x61] = Key::GreaterThan;
m_shift_keymap[0x66] = Key::Backspace;
m_shift_keymap[0x69] = Key::Numpad1;
m_shift_keymap[0x6B] = Key::Numpad4;
m_shift_keymap[0x6C] = Key::Numpad7;
m_shift_keymap[0x70] = Key::Numpad0;
m_shift_keymap[0x71] = Key::NumpadDecimal;
m_shift_keymap[0x72] = Key::Numpad2;
m_shift_keymap[0x73] = Key::Numpad5;
m_shift_keymap[0x74] = Key::Numpad6;
m_shift_keymap[0x75] = Key::Numpad8;
m_shift_keymap[0x76] = Key::Escape;
m_shift_keymap[0x77] = Key::NumLock;
m_shift_keymap[0x78] = Key::F11;
m_shift_keymap[0x79] = Key::NumpadPlus;
m_shift_keymap[0x7A] = Key::Numpad3;
m_shift_keymap[0x7B] = Key::NumpadMinus;
m_shift_keymap[0x7C] = Key::NumpadMultiply;
m_shift_keymap[0x7D] = Key::Numpad9;
m_shift_keymap[0x83] = Key::F7;
MUST(m_altgr_keymap.resize(0xFF, Key::Invalid));
m_altgr_keymap[0x01] = Key::F9;
m_altgr_keymap[0x03] = Key::F5;
m_altgr_keymap[0x04] = Key::F3;
m_altgr_keymap[0x05] = Key::F1;
m_altgr_keymap[0x06] = Key::F2;
m_altgr_keymap[0x07] = Key::F11;
m_altgr_keymap[0x09] = Key::F10;
m_altgr_keymap[0x0A] = Key::F8;
m_altgr_keymap[0x0B] = Key::F6;
m_altgr_keymap[0x0C] = Key::F4;
m_altgr_keymap[0x0D] = Key::Tab;
m_altgr_keymap[0x0E] = Key::None;
m_altgr_keymap[0x11] = Key::Alt;
m_altgr_keymap[0x12] = Key::LeftShift;
m_altgr_keymap[0x14] = Key::LeftCtrl;
m_altgr_keymap[0x15] = Key::Q;
m_altgr_keymap[0x16] = Key::None;
m_altgr_keymap[0x1A] = Key::Z;
m_altgr_keymap[0x1B] = Key::S;
m_altgr_keymap[0x1C] = Key::A;
m_altgr_keymap[0x1D] = Key::W;
m_altgr_keymap[0x1E] = Key::AtSign;
m_altgr_keymap[0x21] = Key::C;
m_altgr_keymap[0x22] = Key::X;
m_altgr_keymap[0x23] = Key::D;
m_altgr_keymap[0x24] = Key::Euro;
m_altgr_keymap[0x25] = Key::Dollar;
m_altgr_keymap[0x26] = Key::Pound;
m_altgr_keymap[0x29] = Key::Space;
m_altgr_keymap[0x2A] = Key::V;
m_altgr_keymap[0x2B] = Key::F;
m_altgr_keymap[0x2C] = Key::T;
m_altgr_keymap[0x2D] = Key::R;
m_altgr_keymap[0x2E] = Key::None;
m_altgr_keymap[0x31] = Key::N;
m_altgr_keymap[0x32] = Key::B;
m_altgr_keymap[0x33] = Key::H;
m_altgr_keymap[0x34] = Key::G;
m_altgr_keymap[0x35] = Key::Y;
m_altgr_keymap[0x36] = Key::None;
m_altgr_keymap[0x3A] = Key::M;
m_altgr_keymap[0x3B] = Key::J;
m_altgr_keymap[0x3C] = Key::U;
m_altgr_keymap[0x3D] = Key::OpenCurlyBrace;
m_altgr_keymap[0x3E] = Key::OpenBrace;
m_altgr_keymap[0x41] = Key::None;
m_altgr_keymap[0x42] = Key::K;
m_altgr_keymap[0x43] = Key::I;
m_altgr_keymap[0x44] = Key::O;
m_altgr_keymap[0x45] = Key::CloseCurlyBrace;
m_altgr_keymap[0x46] = Key::CloseBrace;
m_altgr_keymap[0x49] = Key::None;
m_altgr_keymap[0x4A] = Key::None;
m_altgr_keymap[0x4B] = Key::L;
m_altgr_keymap[0x4C] = Key::O_Umlaut;
m_altgr_keymap[0x4D] = Key::P;
m_altgr_keymap[0x4E] = Key::BackSlash;
m_altgr_keymap[0x52] = Key::A_Umlaut;
m_altgr_keymap[0x54] = Key::A_Ring;
m_altgr_keymap[0x55] = Key::None;
m_altgr_keymap[0x58] = Key::CapsLock;
m_altgr_keymap[0x59] = Key::RightShift;
m_altgr_keymap[0x59] = Key::RightShift;
m_altgr_keymap[0x5A] = Key::Enter;
m_altgr_keymap[0x5B] = Key::Tilde;
m_altgr_keymap[0x5D] = Key::None;
m_altgr_keymap[0x61] = Key::Pipe;
m_altgr_keymap[0x66] = Key::Backspace;
m_altgr_keymap[0x69] = Key::Numpad1;
m_altgr_keymap[0x6B] = Key::Numpad4;
m_altgr_keymap[0x6C] = Key::Numpad7;
m_altgr_keymap[0x70] = Key::Numpad0;
m_altgr_keymap[0x71] = Key::NumpadDecimal;
m_altgr_keymap[0x72] = Key::Numpad2;
m_altgr_keymap[0x73] = Key::Numpad5;
m_altgr_keymap[0x74] = Key::Numpad6;
m_altgr_keymap[0x75] = Key::Numpad8;
m_altgr_keymap[0x76] = Key::Escape;
m_altgr_keymap[0x77] = Key::NumLock;
m_altgr_keymap[0x78] = Key::F11;
m_altgr_keymap[0x79] = Key::NumpadPlus;
m_altgr_keymap[0x7A] = Key::Numpad3;
m_altgr_keymap[0x7B] = Key::NumpadMinus;
m_altgr_keymap[0x7C] = Key::NumpadMultiply;
m_altgr_keymap[0x7D] = Key::Numpad9;
m_altgr_keymap[0x83] = Key::F7;
MUST(m_extended_keymap.resize(0xFF, Key::Invalid));
m_extended_keymap[0x11] = Key::AltGr;
m_extended_keymap[0x14] = Key::RightCtrl;
m_extended_keymap[0x15] = Key::MediaPrevious;
m_extended_keymap[0x1F] = Key::Super;
m_extended_keymap[0x21] = Key::VolumeUp;
m_extended_keymap[0x23] = Key::VolumeMute;
m_extended_keymap[0x2B] = Key::Calculator;
m_extended_keymap[0x32] = Key::VolumeDown;
m_extended_keymap[0x34] = Key::MediaPlayPause;
m_extended_keymap[0x3B] = Key::MediaStop;
m_extended_keymap[0x4A] = Key::NumpadDivide;
m_extended_keymap[0x4D] = Key::MediaNext;
m_extended_keymap[0x5A] = Key::NumpadEnter;
m_extended_keymap[0x69] = Key::End;
m_extended_keymap[0x6B] = Key::ArrowLeft;
m_extended_keymap[0x6C] = Key::Home;
m_extended_keymap[0x70] = Key::Insert;
m_extended_keymap[0x71] = Key::Delete;
m_extended_keymap[0x72] = Key::ArrowDown;
m_extended_keymap[0x74] = Key::ArrowRight;
m_extended_keymap[0x75] = Key::ArrowUp;
m_extended_keymap[0x7A] = Key::PageUp;
m_extended_keymap[0x7D] = Key::PageDown;
memset(m_scancode_to_keycode_normal.data(), 0xFF, m_scancode_to_keycode_normal.size());
memset(m_scancode_to_keycode_extended.data(), 0xFF, m_scancode_to_keycode_extended.size());
if (scancode_set == 1)
return initialize_scancode_set1();
if (scancode_set == 2)
return initialize_scancode_set2();
if (scancode_set == 3)
return initialize_scancode_set3();
ASSERT_NOT_REACHED();
}
Key PS2Keymap::key_for_scancode_and_modifiers(uint32_t scancode, uint8_t modifiers)
BAN::Optional<uint8_t> PS2Keymap::get_keycode(uint8_t scancode, bool extended) const
{
bool extended = scancode & 0x80000000;
scancode &= 0x7FFFFFFF;
KeyEvent dummy;
dummy.modifier = modifiers;
auto& keymap = extended ? m_extended_keymap :
dummy.shift() ? m_shift_keymap :
dummy.altgr() ? m_altgr_keymap :
m_normal_keymap;
if (scancode >= keymap.size())
return Key::Invalid;
Key key = keymap[scancode];
if (!dummy.num_lock() || dummy.shift() || dummy.ctrl() || dummy.alt())
uint8_t keycode = extended ? m_scancode_to_keycode_extended[scancode] : m_scancode_to_keycode_normal[scancode];
if (keycode == 0xFF)
{
switch (key)
{
case Key::Numpad0:
key = Key::Insert;
break;
case Key::Numpad1:
key = Key::End;
break;
case Key::Numpad2:
key = Key::ArrowDown;
break;
case Key::Numpad3:
key = Key::PageDown;
break;
case Key::Numpad4:
key = Key::ArrowLeft;
break;
case Key::Numpad5:
key = Key::None;
break;
case Key::Numpad6:
key = Key::ArrowRight;
break;
case Key::Numpad7:
key = Key::Home;
break;
case Key::Numpad8:
key = Key::ArrowUp;
break;
case Key::Numpad9:
key = Key::PageUp;
break;
case Key::NumpadDecimal:
key = Key::Delete;
break;
default:
break;
}
dprintln("unknown {2H} {}", scancode, extended ? 'E' : ' ');
return {};
}
return keycode;
}
return key;
void PS2Keymap::initialize_scancode_set1()
{
m_scancode_to_keycode_normal[0x29] = keycode_normal(0, 0);
m_scancode_to_keycode_normal[0x02] = keycode_normal(0, 1);
m_scancode_to_keycode_normal[0x03] = keycode_normal(0, 2);
m_scancode_to_keycode_normal[0x04] = keycode_normal(0, 3);
m_scancode_to_keycode_normal[0x05] = keycode_normal(0, 4);
m_scancode_to_keycode_normal[0x06] = keycode_normal(0, 5);
m_scancode_to_keycode_normal[0x07] = keycode_normal(0, 6);
m_scancode_to_keycode_normal[0x08] = keycode_normal(0, 7);
m_scancode_to_keycode_normal[0x09] = keycode_normal(0, 8);
m_scancode_to_keycode_normal[0x0A] = keycode_normal(0, 9);
m_scancode_to_keycode_normal[0x0B] = keycode_normal(0, 10);
m_scancode_to_keycode_normal[0x0C] = keycode_normal(0, 11);
m_scancode_to_keycode_normal[0x0D] = keycode_normal(0, 12);
m_scancode_to_keycode_normal[0x0E] = keycode_normal(0, 13);
m_scancode_to_keycode_normal[0x0F] = keycode_normal(1, 0);
m_scancode_to_keycode_normal[0x10] = keycode_normal(1, 1);
m_scancode_to_keycode_normal[0x11] = keycode_normal(1, 2);
m_scancode_to_keycode_normal[0x12] = keycode_normal(1, 3);
m_scancode_to_keycode_normal[0x13] = keycode_normal(1, 4);
m_scancode_to_keycode_normal[0x14] = keycode_normal(1, 5);
m_scancode_to_keycode_normal[0x15] = keycode_normal(1, 6);
m_scancode_to_keycode_normal[0x16] = keycode_normal(1, 7);
m_scancode_to_keycode_normal[0x17] = keycode_normal(1, 8);
m_scancode_to_keycode_normal[0x18] = keycode_normal(1, 9);
m_scancode_to_keycode_normal[0x19] = keycode_normal(1, 10);
m_scancode_to_keycode_normal[0x1A] = keycode_normal(1, 11);
m_scancode_to_keycode_normal[0x1B] = keycode_normal(1, 12);
m_scancode_to_keycode_normal[0x3A] = keycode_normal(2, 0);
m_scancode_to_keycode_normal[0x1E] = keycode_normal(2, 1);
m_scancode_to_keycode_normal[0x1F] = keycode_normal(2, 2);
m_scancode_to_keycode_normal[0x20] = keycode_normal(2, 3);
m_scancode_to_keycode_normal[0x21] = keycode_normal(2, 4);
m_scancode_to_keycode_normal[0x22] = keycode_normal(2, 5);
m_scancode_to_keycode_normal[0x23] = keycode_normal(2, 6);
m_scancode_to_keycode_normal[0x24] = keycode_normal(2, 7);
m_scancode_to_keycode_normal[0x25] = keycode_normal(2, 8);
m_scancode_to_keycode_normal[0x26] = keycode_normal(2, 9);
m_scancode_to_keycode_normal[0x27] = keycode_normal(2, 10);
m_scancode_to_keycode_normal[0x28] = keycode_normal(2, 11);
m_scancode_to_keycode_normal[0x2B] = keycode_normal(2, 12);
m_scancode_to_keycode_normal[0x1C] = keycode_normal(2, 13);
m_scancode_to_keycode_normal[0x2A] = keycode_normal(3, 0);
m_scancode_to_keycode_normal[0x56] = keycode_normal(3, 1);
m_scancode_to_keycode_normal[0x2C] = keycode_normal(3, 2);
m_scancode_to_keycode_normal[0x2D] = keycode_normal(3, 3);
m_scancode_to_keycode_normal[0x2E] = keycode_normal(3, 4);
m_scancode_to_keycode_normal[0x2F] = keycode_normal(3, 5);
m_scancode_to_keycode_normal[0x30] = keycode_normal(3, 6);
m_scancode_to_keycode_normal[0x31] = keycode_normal(3, 7);
m_scancode_to_keycode_normal[0x32] = keycode_normal(3, 8);
m_scancode_to_keycode_normal[0x33] = keycode_normal(3, 9);
m_scancode_to_keycode_normal[0x34] = keycode_normal(3, 10);
m_scancode_to_keycode_normal[0x35] = keycode_normal(3, 11);
m_scancode_to_keycode_normal[0x36] = keycode_normal(3, 12);
m_scancode_to_keycode_normal[0x1D] = keycode_normal(4, 0);
m_scancode_to_keycode_extended[0x5B] = keycode_normal(4, 1);
m_scancode_to_keycode_normal[0x38] = keycode_normal(4, 2);
m_scancode_to_keycode_normal[0x39] = keycode_normal(4, 3);
m_scancode_to_keycode_extended[0x38] = keycode_normal(4, 4);
m_scancode_to_keycode_extended[0x1D] = keycode_normal(4, 5);
m_scancode_to_keycode_normal[0x45] = keycode_numpad(0, 0);
m_scancode_to_keycode_extended[0x35] = keycode_numpad(0, 1);
m_scancode_to_keycode_normal[0x37] = keycode_numpad(0, 2);
m_scancode_to_keycode_normal[0x4A] = keycode_numpad(0, 3);
m_scancode_to_keycode_normal[0x47] = keycode_numpad(1, 0);
m_scancode_to_keycode_normal[0x48] = keycode_numpad(1, 1);
m_scancode_to_keycode_normal[0x49] = keycode_numpad(1, 2);
m_scancode_to_keycode_normal[0x4E] = keycode_numpad(1, 3);
m_scancode_to_keycode_normal[0x4B] = keycode_numpad(2, 0);
m_scancode_to_keycode_normal[0x4C] = keycode_numpad(2, 1);
m_scancode_to_keycode_normal[0x4D] = keycode_numpad(2, 2);
m_scancode_to_keycode_normal[0x4F] = keycode_numpad(3, 0);
m_scancode_to_keycode_normal[0x50] = keycode_numpad(3, 1);
m_scancode_to_keycode_normal[0x51] = keycode_numpad(3, 2);
m_scancode_to_keycode_extended[0x1C] = keycode_numpad(3, 3);
m_scancode_to_keycode_normal[0x52] = keycode_numpad(4, 0);
m_scancode_to_keycode_normal[0x53] = keycode_numpad(4, 1);
m_scancode_to_keycode_normal[0x01] = keycode_function( 0);
m_scancode_to_keycode_normal[0x3B] = keycode_function( 1);
m_scancode_to_keycode_normal[0x3C] = keycode_function( 2);
m_scancode_to_keycode_normal[0x3D] = keycode_function( 3);
m_scancode_to_keycode_normal[0x3E] = keycode_function( 4);
m_scancode_to_keycode_normal[0x3F] = keycode_function( 5);
m_scancode_to_keycode_normal[0x40] = keycode_function( 6);
m_scancode_to_keycode_normal[0x41] = keycode_function( 7);
m_scancode_to_keycode_normal[0x42] = keycode_function( 8);
m_scancode_to_keycode_normal[0x43] = keycode_function( 9);
m_scancode_to_keycode_normal[0x44] = keycode_function(10);
m_scancode_to_keycode_normal[0x57] = keycode_function(11);
m_scancode_to_keycode_normal[0x58] = keycode_function(12);
m_scancode_to_keycode_extended[0x52] = keycode_function(13);
//m_scancode_to_keycode_normal[0x] = keycode_function(14);
m_scancode_to_keycode_extended[0x53] = keycode_function(15);
m_scancode_to_keycode_extended[0x47] = keycode_function(16);
m_scancode_to_keycode_extended[0x4F] = keycode_function(17);
m_scancode_to_keycode_extended[0x49] = keycode_function(18);
m_scancode_to_keycode_extended[0x51] = keycode_function(19);
m_scancode_to_keycode_normal[0x46] = keycode_function(20);
// Arrow keys
m_scancode_to_keycode_extended[0x48] = keycode_normal(5, 0);
m_scancode_to_keycode_extended[0x4B] = keycode_normal(5, 1);
m_scancode_to_keycode_extended[0x50] = keycode_normal(5, 2);
m_scancode_to_keycode_extended[0x4D] = keycode_normal(5, 3);
}
void PS2Keymap::initialize_scancode_set2()
{
m_scancode_to_keycode_normal[0x0E] = keycode_normal(0, 0);
m_scancode_to_keycode_normal[0x16] = keycode_normal(0, 1);
m_scancode_to_keycode_normal[0x1E] = keycode_normal(0, 2);
m_scancode_to_keycode_normal[0x26] = keycode_normal(0, 3);
m_scancode_to_keycode_normal[0x25] = keycode_normal(0, 4);
m_scancode_to_keycode_normal[0x2E] = keycode_normal(0, 5);
m_scancode_to_keycode_normal[0x36] = keycode_normal(0, 6);
m_scancode_to_keycode_normal[0x3D] = keycode_normal(0, 7);
m_scancode_to_keycode_normal[0x3E] = keycode_normal(0, 8);
m_scancode_to_keycode_normal[0x46] = keycode_normal(0, 9);
m_scancode_to_keycode_normal[0x45] = keycode_normal(0, 10);
m_scancode_to_keycode_normal[0x4E] = keycode_normal(0, 11);
m_scancode_to_keycode_normal[0x55] = keycode_normal(0, 12);
m_scancode_to_keycode_normal[0x66] = keycode_normal(0, 13);
m_scancode_to_keycode_normal[0x0D] = keycode_normal(1, 0);
m_scancode_to_keycode_normal[0x15] = keycode_normal(1, 1);
m_scancode_to_keycode_normal[0x1D] = keycode_normal(1, 2);
m_scancode_to_keycode_normal[0x24] = keycode_normal(1, 3);
m_scancode_to_keycode_normal[0x2D] = keycode_normal(1, 4);
m_scancode_to_keycode_normal[0x2C] = keycode_normal(1, 5);
m_scancode_to_keycode_normal[0x35] = keycode_normal(1, 6);
m_scancode_to_keycode_normal[0x3C] = keycode_normal(1, 7);
m_scancode_to_keycode_normal[0x43] = keycode_normal(1, 8);
m_scancode_to_keycode_normal[0x44] = keycode_normal(1, 9);
m_scancode_to_keycode_normal[0x4D] = keycode_normal(1, 10);
m_scancode_to_keycode_normal[0x54] = keycode_normal(1, 11);
m_scancode_to_keycode_normal[0x5B] = keycode_normal(1, 12);
m_scancode_to_keycode_normal[0x58] = keycode_normal(2, 0);
m_scancode_to_keycode_normal[0x1C] = keycode_normal(2, 1);
m_scancode_to_keycode_normal[0x1B] = keycode_normal(2, 2);
m_scancode_to_keycode_normal[0x23] = keycode_normal(2, 3);
m_scancode_to_keycode_normal[0x2B] = keycode_normal(2, 4);
m_scancode_to_keycode_normal[0x34] = keycode_normal(2, 5);
m_scancode_to_keycode_normal[0x33] = keycode_normal(2, 6);
m_scancode_to_keycode_normal[0x3B] = keycode_normal(2, 7);
m_scancode_to_keycode_normal[0x42] = keycode_normal(2, 8);
m_scancode_to_keycode_normal[0x4B] = keycode_normal(2, 9);
m_scancode_to_keycode_normal[0x4C] = keycode_normal(2, 10);
m_scancode_to_keycode_normal[0x52] = keycode_normal(2, 11);
m_scancode_to_keycode_normal[0x5D] = keycode_normal(2, 12);
m_scancode_to_keycode_normal[0x5A] = keycode_normal(2, 13);
m_scancode_to_keycode_normal[0x12] = keycode_normal(3, 0);
m_scancode_to_keycode_normal[0x61] = keycode_normal(3, 1);
m_scancode_to_keycode_normal[0x1A] = keycode_normal(3, 2);
m_scancode_to_keycode_normal[0x22] = keycode_normal(3, 3);
m_scancode_to_keycode_normal[0x21] = keycode_normal(3, 4);
m_scancode_to_keycode_normal[0x2A] = keycode_normal(3, 5);
m_scancode_to_keycode_normal[0x32] = keycode_normal(3, 6);
m_scancode_to_keycode_normal[0x31] = keycode_normal(3, 7);
m_scancode_to_keycode_normal[0x3A] = keycode_normal(3, 8);
m_scancode_to_keycode_normal[0x41] = keycode_normal(3, 9);
m_scancode_to_keycode_normal[0x49] = keycode_normal(3, 10);
m_scancode_to_keycode_normal[0x4A] = keycode_normal(3, 11);
m_scancode_to_keycode_normal[0x59] = keycode_normal(3, 12);
m_scancode_to_keycode_normal[0x14] = keycode_normal(4, 1);
m_scancode_to_keycode_extended[0x1F] = keycode_normal(4, 2);
m_scancode_to_keycode_normal[0x11] = keycode_normal(4, 3);
m_scancode_to_keycode_normal[0x29] = keycode_normal(4, 4);
m_scancode_to_keycode_extended[0x11] = keycode_normal(4, 5);
m_scancode_to_keycode_extended[0x14] = keycode_normal(4, 6);
m_scancode_to_keycode_normal[0x77] = keycode_numpad(0, 0);
m_scancode_to_keycode_extended[0x4A] = keycode_numpad(0, 1);
m_scancode_to_keycode_normal[0x7C] = keycode_numpad(0, 2);
m_scancode_to_keycode_normal[0x7B] = keycode_numpad(0, 3);
m_scancode_to_keycode_normal[0x6C] = keycode_numpad(1, 0);
m_scancode_to_keycode_normal[0x75] = keycode_numpad(1, 1);
m_scancode_to_keycode_normal[0x7D] = keycode_numpad(1, 2);
m_scancode_to_keycode_normal[0x79] = keycode_numpad(1, 3);
m_scancode_to_keycode_normal[0x6B] = keycode_numpad(2, 0);
m_scancode_to_keycode_normal[0x73] = keycode_numpad(2, 1);
m_scancode_to_keycode_normal[0x74] = keycode_numpad(2, 2);
m_scancode_to_keycode_normal[0x69] = keycode_numpad(3, 0);
m_scancode_to_keycode_normal[0x72] = keycode_numpad(3, 1);
m_scancode_to_keycode_normal[0x7A] = keycode_numpad(3, 2);
m_scancode_to_keycode_extended[0x5A] = keycode_numpad(3, 3);
m_scancode_to_keycode_normal[0x70] = keycode_numpad(4, 0);
m_scancode_to_keycode_normal[0x71] = keycode_numpad(4, 1);
m_scancode_to_keycode_normal[0x76] = keycode_function( 0);
m_scancode_to_keycode_normal[0x05] = keycode_function( 1);
m_scancode_to_keycode_normal[0x06] = keycode_function( 2);
m_scancode_to_keycode_normal[0x04] = keycode_function( 3);
m_scancode_to_keycode_normal[0x0C] = keycode_function( 4);
m_scancode_to_keycode_normal[0x03] = keycode_function( 5);
m_scancode_to_keycode_normal[0x0B] = keycode_function( 6);
m_scancode_to_keycode_normal[0x83] = keycode_function( 7);
m_scancode_to_keycode_normal[0x0A] = keycode_function( 8);
m_scancode_to_keycode_normal[0x01] = keycode_function( 9);
m_scancode_to_keycode_normal[0x09] = keycode_function(10);
m_scancode_to_keycode_normal[0x78] = keycode_function(11);
m_scancode_to_keycode_normal[0x07] = keycode_function(12);
m_scancode_to_keycode_extended[0x70] = keycode_function(13);
//m_scancode_to_keycode_normal[0x] = keycode_function(14);
m_scancode_to_keycode_extended[0x71] = keycode_function(15);
m_scancode_to_keycode_extended[0x6C] = keycode_function(16);
m_scancode_to_keycode_extended[0x69] = keycode_function(17);
m_scancode_to_keycode_extended[0x7D] = keycode_function(18);
m_scancode_to_keycode_extended[0x7A] = keycode_function(19);
m_scancode_to_keycode_normal[0x7E] = keycode_function(20);
// Arrow keys
m_scancode_to_keycode_extended[0x75] = keycode_normal(5, 0);
m_scancode_to_keycode_extended[0x6B] = keycode_normal(5, 1);
m_scancode_to_keycode_extended[0x72] = keycode_normal(5, 2);
m_scancode_to_keycode_extended[0x74] = keycode_normal(5, 3);
}
void PS2Keymap::initialize_scancode_set3()
{
m_scancode_to_keycode_normal[0x0E] = keycode_normal(0, 0);
m_scancode_to_keycode_normal[0x16] = keycode_normal(0, 1);
m_scancode_to_keycode_normal[0x1E] = keycode_normal(0, 2);
m_scancode_to_keycode_normal[0x26] = keycode_normal(0, 3);
m_scancode_to_keycode_normal[0x25] = keycode_normal(0, 4);
m_scancode_to_keycode_normal[0x2E] = keycode_normal(0, 5);
m_scancode_to_keycode_normal[0x36] = keycode_normal(0, 6);
m_scancode_to_keycode_normal[0x3D] = keycode_normal(0, 7);
m_scancode_to_keycode_normal[0x3E] = keycode_normal(0, 8);
m_scancode_to_keycode_normal[0x46] = keycode_normal(0, 9);
m_scancode_to_keycode_normal[0x45] = keycode_normal(0, 10);
m_scancode_to_keycode_normal[0x4E] = keycode_normal(0, 11);
m_scancode_to_keycode_normal[0x55] = keycode_normal(0, 12);
m_scancode_to_keycode_normal[0x66] = keycode_normal(0, 13);
m_scancode_to_keycode_normal[0x0D] = keycode_normal(1, 0);
m_scancode_to_keycode_normal[0x15] = keycode_normal(1, 1);
m_scancode_to_keycode_normal[0x1D] = keycode_normal(1, 2);
m_scancode_to_keycode_normal[0x24] = keycode_normal(1, 3);
m_scancode_to_keycode_normal[0x2D] = keycode_normal(1, 4);
m_scancode_to_keycode_normal[0x2C] = keycode_normal(1, 5);
m_scancode_to_keycode_normal[0x35] = keycode_normal(1, 6);
m_scancode_to_keycode_normal[0x3C] = keycode_normal(1, 7);
m_scancode_to_keycode_normal[0x43] = keycode_normal(1, 8);
m_scancode_to_keycode_normal[0x44] = keycode_normal(1, 9);
m_scancode_to_keycode_normal[0x4D] = keycode_normal(1, 10);
m_scancode_to_keycode_normal[0x54] = keycode_normal(1, 11);
m_scancode_to_keycode_normal[0x5B] = keycode_normal(1, 12);
m_scancode_to_keycode_normal[0x14] = keycode_normal(2, 0);
m_scancode_to_keycode_normal[0x1C] = keycode_normal(2, 1);
m_scancode_to_keycode_normal[0x1B] = keycode_normal(2, 2);
m_scancode_to_keycode_normal[0x23] = keycode_normal(2, 3);
m_scancode_to_keycode_normal[0x2B] = keycode_normal(2, 4);
m_scancode_to_keycode_normal[0x34] = keycode_normal(2, 5);
m_scancode_to_keycode_normal[0x33] = keycode_normal(2, 6);
m_scancode_to_keycode_normal[0x3B] = keycode_normal(2, 7);
m_scancode_to_keycode_normal[0x42] = keycode_normal(2, 8);
m_scancode_to_keycode_normal[0x4B] = keycode_normal(2, 9);
m_scancode_to_keycode_normal[0x4C] = keycode_normal(2, 10);
m_scancode_to_keycode_normal[0x52] = keycode_normal(2, 11);
m_scancode_to_keycode_normal[0x5C] = keycode_normal(2, 12);
m_scancode_to_keycode_normal[0x5A] = keycode_normal(2, 13);
m_scancode_to_keycode_normal[0x12] = keycode_normal(3, 0);
m_scancode_to_keycode_normal[0x13] = keycode_normal(3, 1);
m_scancode_to_keycode_normal[0x1A] = keycode_normal(3, 2);
m_scancode_to_keycode_normal[0x22] = keycode_normal(3, 3);
m_scancode_to_keycode_normal[0x21] = keycode_normal(3, 4);
m_scancode_to_keycode_normal[0x2A] = keycode_normal(3, 5);
m_scancode_to_keycode_normal[0x32] = keycode_normal(3, 6);
m_scancode_to_keycode_normal[0x31] = keycode_normal(3, 7);
m_scancode_to_keycode_normal[0x3A] = keycode_normal(3, 8);
m_scancode_to_keycode_normal[0x41] = keycode_normal(3, 9);
m_scancode_to_keycode_normal[0x49] = keycode_normal(3, 10);
m_scancode_to_keycode_normal[0x4A] = keycode_normal(3, 11);
m_scancode_to_keycode_normal[0x59] = keycode_normal(3, 12);
m_scancode_to_keycode_normal[0x11] = keycode_normal(4, 0);
m_scancode_to_keycode_normal[0x8B] = keycode_normal(4, 1);
m_scancode_to_keycode_normal[0x19] = keycode_normal(4, 2);
m_scancode_to_keycode_normal[0x29] = keycode_normal(4, 3);
m_scancode_to_keycode_normal[0x39] = keycode_normal(4, 4);
m_scancode_to_keycode_normal[0x58] = keycode_normal(4, 5);
m_scancode_to_keycode_normal[0x76] = keycode_numpad(0, 0);
//m_scancode_to_keycode_normal[0x] = keycode_numpad(0, 1);
m_scancode_to_keycode_normal[0x7E] = keycode_numpad(0, 2);
//m_scancode_to_keycode_normal[0x] = keycode_numpad(0, 3);
m_scancode_to_keycode_normal[0x6C] = keycode_numpad(1, 1);
m_scancode_to_keycode_normal[0x75] = keycode_numpad(1, 2);
m_scancode_to_keycode_normal[0x7D] = keycode_numpad(1, 3);
m_scancode_to_keycode_normal[0x7C] = keycode_numpad(1, 4);
m_scancode_to_keycode_normal[0x6B] = keycode_numpad(2, 1);
m_scancode_to_keycode_normal[0x73] = keycode_numpad(2, 2);
m_scancode_to_keycode_normal[0x74] = keycode_numpad(2, 3);
m_scancode_to_keycode_normal[0x69] = keycode_numpad(3, 1);
m_scancode_to_keycode_normal[0x72] = keycode_numpad(3, 2);
m_scancode_to_keycode_normal[0x7A] = keycode_numpad(3, 3);
m_scancode_to_keycode_normal[0x79] = keycode_numpad(3, 4);
m_scancode_to_keycode_normal[0x70] = keycode_numpad(4, 1);
m_scancode_to_keycode_normal[0x71] = keycode_numpad(4, 2);
m_scancode_to_keycode_normal[0x08] = keycode_function(0);
m_scancode_to_keycode_normal[0x07] = keycode_function(1);
m_scancode_to_keycode_normal[0x0F] = keycode_function(2);
m_scancode_to_keycode_normal[0x17] = keycode_function(3);
m_scancode_to_keycode_normal[0x1F] = keycode_function(4);
m_scancode_to_keycode_normal[0x27] = keycode_function(5);
m_scancode_to_keycode_normal[0x2F] = keycode_function(6);
m_scancode_to_keycode_normal[0x37] = keycode_function(7);
m_scancode_to_keycode_normal[0x3F] = keycode_function(8);
m_scancode_to_keycode_normal[0x47] = keycode_function(9);
m_scancode_to_keycode_normal[0x4F] = keycode_function(10);
m_scancode_to_keycode_normal[0x56] = keycode_function(11);
m_scancode_to_keycode_normal[0x5E] = keycode_function(12);
m_scancode_to_keycode_normal[0x67] = keycode_function(13);
m_scancode_to_keycode_normal[0x57] = keycode_function(14);
m_scancode_to_keycode_normal[0x64] = keycode_function(15);
m_scancode_to_keycode_normal[0x6E] = keycode_function(16);
m_scancode_to_keycode_normal[0x65] = keycode_function(17);
m_scancode_to_keycode_normal[0x6F] = keycode_function(18);
m_scancode_to_keycode_normal[0x6D] = keycode_function(19);
m_scancode_to_keycode_normal[0x5F] = keycode_function(20);
// Arrow keys
m_scancode_to_keycode_normal[0x63] = keycode_normal(5, 0);
m_scancode_to_keycode_normal[0x61] = keycode_normal(5, 1);
m_scancode_to_keycode_normal[0x60] = keycode_normal(5, 2);
m_scancode_to_keycode_normal[0x6A] = keycode_normal(5, 3);
}
}

View File

@ -127,12 +127,13 @@ namespace Kernel
if (event.released())
return;
const char* ansi_c_str = Input::key_event_to_utf8(event);
Input::Key key = Input::key_event_to_key(event);
const char* ansi_c_str = Input::key_to_utf8(key, event.modifier);
if (event.ctrl())
{
ansi_c_str = nullptr;
switch (event.key)
ansi_c_str = nullptr;
switch (key)
{
case Input::Key::A: ansi_c_str = "\x01"; break;
case Input::Key::B: ansi_c_str = "\x02"; break;
@ -165,7 +166,7 @@ namespace Kernel
}
else
{
switch (event.key)
switch (key)
{
case Input::Key::Enter:
case Input::Key::NumpadEnter:

View File

@ -8,6 +8,7 @@
#include <kernel/FS/VirtualFileSystem.h>
#include <kernel/GDT.h>
#include <kernel/IDT.h>
#include <kernel/Input/KeyboardLayouts/FI.h>
#include <kernel/Input/PS2/Controller.h>
#include <kernel/InterruptController.h>
#include <kernel/kprint.h>
@ -182,6 +183,7 @@ static void init2(void*)
VirtualFileSystem::initialize(cmdline.root);
dprintln("VFS initialized");
Input::KeyboardLayout::initialize_fi();
if (auto res = PS2Controller::initialize(); res.is_error())
dprintln("{}", res.error());