mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 03:57:44 +00:00
Flesh out keyboard event support a bit more.
This commit is contained in:
parent
76a2881793
commit
aefbbeb3cb
7 changed files with 196 additions and 84 deletions
|
@ -158,12 +158,9 @@ void WSEventLoop::drain_keyboard()
|
|||
auto& screen = WSScreen::the();
|
||||
auto& keyboard = Keyboard::the();
|
||||
while (keyboard.can_read(*m_server_process)) {
|
||||
byte data[2];
|
||||
ssize_t nread = keyboard.read(*m_server_process, (byte*)data, sizeof(data));
|
||||
ASSERT(nread == sizeof(data));
|
||||
Keyboard::Key key;
|
||||
key.character = data[0];
|
||||
key.modifiers = data[1];
|
||||
screen.on_receive_keyboard_data(key);
|
||||
Keyboard::Event event;
|
||||
ssize_t nread = keyboard.read(*m_server_process, (byte*)&event, sizeof(Keyboard::Event));
|
||||
ASSERT(nread == sizeof(Keyboard::Event));
|
||||
screen.on_receive_keyboard_data(event);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -66,9 +66,9 @@ void WSScreen::on_receive_mouse_data(int dx, int dy, bool left_button, bool righ
|
|||
WSWindowManager::the().draw_cursor();
|
||||
}
|
||||
|
||||
void WSScreen::on_receive_keyboard_data(Keyboard::Key key)
|
||||
void WSScreen::on_receive_keyboard_data(Keyboard::Event key)
|
||||
{
|
||||
auto event = make<KeyEvent>(WSEvent::KeyDown, 0);
|
||||
auto event = make<KeyEvent>(key.is_press() ? WSEvent::KeyDown : WSEvent::KeyUp, 0);
|
||||
int key_code = 0;
|
||||
|
||||
switch (key.character) {
|
||||
|
@ -81,35 +81,6 @@ void WSScreen::on_receive_keyboard_data(Keyboard::Key key)
|
|||
char buf[] = { 0, 0 };
|
||||
char& ch = buf[0];
|
||||
ch = key.character;
|
||||
if (key.shift()) {
|
||||
if (ch >= 'a' && ch <= 'z') {
|
||||
ch &= ~0x20;
|
||||
} else {
|
||||
switch (ch) {
|
||||
case '1': ch = '!'; break;
|
||||
case '2': ch = '@'; break;
|
||||
case '3': ch = '#'; break;
|
||||
case '4': ch = '$'; break;
|
||||
case '5': ch = '%'; break;
|
||||
case '6': ch = '^'; break;
|
||||
case '7': ch = '&'; break;
|
||||
case '8': ch = '*'; break;
|
||||
case '9': ch = '('; break;
|
||||
case '0': ch = ')'; break;
|
||||
case '-': ch = '_'; break;
|
||||
case '=': ch = '+'; break;
|
||||
case '`': ch = '~'; break;
|
||||
case ',': ch = '<'; break;
|
||||
case '.': ch = '>'; break;
|
||||
case '/': ch = '?'; break;
|
||||
case '[': ch = '{'; break;
|
||||
case ']': ch = '}'; break;
|
||||
case '\\': ch = '|'; break;
|
||||
case '\'': ch = '"'; break;
|
||||
case ';': ch = ':'; break;
|
||||
}
|
||||
}
|
||||
}
|
||||
event->m_text = buf;
|
||||
}
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ public:
|
|||
bool right_mouse_button_pressed() const { return m_right_mouse_button_pressed; }
|
||||
|
||||
void on_receive_mouse_data(int dx, int dy, bool left_button, bool right_button);
|
||||
void on_receive_keyboard_data(Keyboard::Key);
|
||||
void on_receive_keyboard_data(Keyboard::Event);
|
||||
|
||||
protected:
|
||||
WSScreen(unsigned width, unsigned height);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue