mirror of
https://github.com/qemu/qemu.git
synced 2026-07-08 17:46:10 +00:00
hw/m68k/next-kbd: Use Linux key codes
QemuInputEvent now stores Linux key codes for key events. Use those codes directly instead of translating between internal key code representations. Signed-off-by: Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp> Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com> Message-ID: <20260520-input-v3-15-7c9e4c7abe34@rsg.ci.i.u-tokyo.ac.jp>
This commit is contained in:
committed by
Marc-André Lureau
parent
d5e8b698ec
commit
7725e540a3
@@ -31,6 +31,7 @@
|
||||
#include "qemu/log.h"
|
||||
#include "hw/core/sysbus.h"
|
||||
#include "hw/m68k/next-cube.h"
|
||||
#include "standard-headers/linux/input-event-codes.h"
|
||||
#include "ui/console.h"
|
||||
#include "migration/vmstate.h"
|
||||
#include "qom/object.h"
|
||||
@@ -165,59 +166,59 @@ static const MemoryRegionOps kbd_ops = {
|
||||
.endianness = DEVICE_BIG_ENDIAN,
|
||||
};
|
||||
|
||||
static const int qcode_to_nextkbd_keycode[] = {
|
||||
[Q_KEY_CODE_ESC] = 0x49,
|
||||
[Q_KEY_CODE_1] = 0x4a,
|
||||
[Q_KEY_CODE_2] = 0x4b,
|
||||
[Q_KEY_CODE_3] = 0x4c,
|
||||
[Q_KEY_CODE_4] = 0x4d,
|
||||
[Q_KEY_CODE_5] = 0x50,
|
||||
[Q_KEY_CODE_6] = 0x4f,
|
||||
[Q_KEY_CODE_7] = 0x4e,
|
||||
[Q_KEY_CODE_8] = 0x1e,
|
||||
[Q_KEY_CODE_9] = 0x1f,
|
||||
[Q_KEY_CODE_0] = 0x20,
|
||||
[Q_KEY_CODE_MINUS] = 0x1d,
|
||||
[Q_KEY_CODE_EQUAL] = 0x1c,
|
||||
[Q_KEY_CODE_BACKSPACE] = 0x1b,
|
||||
static const int linux_to_nextkbd_keycode[] = {
|
||||
[KEY_ESC] = 0x49,
|
||||
[KEY_1] = 0x4a,
|
||||
[KEY_2] = 0x4b,
|
||||
[KEY_3] = 0x4c,
|
||||
[KEY_4] = 0x4d,
|
||||
[KEY_5] = 0x50,
|
||||
[KEY_6] = 0x4f,
|
||||
[KEY_7] = 0x4e,
|
||||
[KEY_8] = 0x1e,
|
||||
[KEY_9] = 0x1f,
|
||||
[KEY_0] = 0x20,
|
||||
[KEY_MINUS] = 0x1d,
|
||||
[KEY_EQUAL] = 0x1c,
|
||||
[KEY_BACKSPACE] = 0x1b,
|
||||
|
||||
[Q_KEY_CODE_Q] = 0x42,
|
||||
[Q_KEY_CODE_W] = 0x43,
|
||||
[Q_KEY_CODE_E] = 0x44,
|
||||
[Q_KEY_CODE_R] = 0x45,
|
||||
[Q_KEY_CODE_T] = 0x48,
|
||||
[Q_KEY_CODE_Y] = 0x47,
|
||||
[Q_KEY_CODE_U] = 0x46,
|
||||
[Q_KEY_CODE_I] = 0x06,
|
||||
[Q_KEY_CODE_O] = 0x07,
|
||||
[Q_KEY_CODE_P] = 0x08,
|
||||
[Q_KEY_CODE_RET] = 0x2a,
|
||||
[Q_KEY_CODE_A] = 0x39,
|
||||
[Q_KEY_CODE_S] = 0x3a,
|
||||
[KEY_Q] = 0x42,
|
||||
[KEY_W] = 0x43,
|
||||
[KEY_E] = 0x44,
|
||||
[KEY_R] = 0x45,
|
||||
[KEY_T] = 0x48,
|
||||
[KEY_Y] = 0x47,
|
||||
[KEY_U] = 0x46,
|
||||
[KEY_I] = 0x06,
|
||||
[KEY_O] = 0x07,
|
||||
[KEY_P] = 0x08,
|
||||
[KEY_ENTER] = 0x2a,
|
||||
[KEY_A] = 0x39,
|
||||
[KEY_S] = 0x3a,
|
||||
|
||||
[Q_KEY_CODE_D] = 0x3b,
|
||||
[Q_KEY_CODE_F] = 0x3c,
|
||||
[Q_KEY_CODE_G] = 0x3d,
|
||||
[Q_KEY_CODE_H] = 0x40,
|
||||
[Q_KEY_CODE_J] = 0x3f,
|
||||
[Q_KEY_CODE_K] = 0x3e,
|
||||
[Q_KEY_CODE_L] = 0x2d,
|
||||
[Q_KEY_CODE_SEMICOLON] = 0x2c,
|
||||
[Q_KEY_CODE_APOSTROPHE] = 0x2b,
|
||||
[Q_KEY_CODE_GRAVE_ACCENT] = 0x26,
|
||||
[Q_KEY_CODE_Z] = 0x31,
|
||||
[Q_KEY_CODE_X] = 0x32,
|
||||
[Q_KEY_CODE_C] = 0x33,
|
||||
[Q_KEY_CODE_V] = 0x34,
|
||||
[KEY_D] = 0x3b,
|
||||
[KEY_F] = 0x3c,
|
||||
[KEY_G] = 0x3d,
|
||||
[KEY_H] = 0x40,
|
||||
[KEY_J] = 0x3f,
|
||||
[KEY_K] = 0x3e,
|
||||
[KEY_L] = 0x2d,
|
||||
[KEY_SEMICOLON] = 0x2c,
|
||||
[KEY_APOSTROPHE] = 0x2b,
|
||||
[KEY_GRAVE] = 0x26,
|
||||
[KEY_Z] = 0x31,
|
||||
[KEY_X] = 0x32,
|
||||
[KEY_C] = 0x33,
|
||||
[KEY_V] = 0x34,
|
||||
|
||||
[Q_KEY_CODE_B] = 0x35,
|
||||
[Q_KEY_CODE_N] = 0x37,
|
||||
[Q_KEY_CODE_M] = 0x36,
|
||||
[Q_KEY_CODE_COMMA] = 0x2e,
|
||||
[Q_KEY_CODE_DOT] = 0x2f,
|
||||
[Q_KEY_CODE_SLASH] = 0x30,
|
||||
[KEY_B] = 0x35,
|
||||
[KEY_N] = 0x37,
|
||||
[KEY_M] = 0x36,
|
||||
[KEY_COMMA] = 0x2e,
|
||||
[KEY_DOT] = 0x2f,
|
||||
[KEY_SLASH] = 0x30,
|
||||
|
||||
[Q_KEY_CODE_SPC] = 0x38,
|
||||
[KEY_SPACE] = 0x38,
|
||||
};
|
||||
|
||||
static void nextkbd_put_keycode(NextKBDState *s, int keycode)
|
||||
@@ -246,15 +247,14 @@ static void nextkbd_event(DeviceState *dev, QemuConsole *src,
|
||||
QemuInputEvent *evt)
|
||||
{
|
||||
NextKBDState *s = NEXTKBD(dev);
|
||||
int qcode, keycode;
|
||||
int keycode;
|
||||
|
||||
qcode = qemu_input_linux_to_qcode(evt->key.key);
|
||||
if (qcode >= ARRAY_SIZE(qcode_to_nextkbd_keycode)) {
|
||||
if (evt->key.key >= ARRAY_SIZE(linux_to_nextkbd_keycode)) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* Shift key currently has no keycode, so handle separately */
|
||||
if (qcode == Q_KEY_CODE_SHIFT) {
|
||||
if (evt->key.key == KEY_LEFTSHIFT) {
|
||||
if (evt->key.down) {
|
||||
s->shift |= KD_LSHIFT;
|
||||
} else {
|
||||
@@ -262,7 +262,7 @@ static void nextkbd_event(DeviceState *dev, QemuConsole *src,
|
||||
}
|
||||
}
|
||||
|
||||
if (qcode == Q_KEY_CODE_SHIFT_R) {
|
||||
if (evt->key.key == KEY_RIGHTSHIFT) {
|
||||
if (evt->key.down) {
|
||||
s->shift |= KD_RSHIFT;
|
||||
} else {
|
||||
@@ -270,7 +270,7 @@ static void nextkbd_event(DeviceState *dev, QemuConsole *src,
|
||||
}
|
||||
}
|
||||
|
||||
keycode = qcode_to_nextkbd_keycode[qcode];
|
||||
keycode = linux_to_nextkbd_keycode[evt->key.key];
|
||||
if (!keycode) {
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user