Properly handle shifted keys. Allow ignoring keyboard modifiers.
This commit is contained in:
parent
07b5b504ae
commit
7232d1bf6f
|
@ -59,6 +59,8 @@ uint8_t kbuf[KBUF_SIZE];
|
|||
uint8_t khead, klen;
|
||||
uint16_t kint;
|
||||
|
||||
bool ignore_modifiers = false;
|
||||
|
||||
void update_glyph_tiles()
|
||||
{
|
||||
SDL_SetSurfacePalette(glyph_shapes, palette);
|
||||
|
@ -160,15 +162,14 @@ void lem1802_free()
|
|||
// SDL_Quit();
|
||||
}
|
||||
|
||||
void process_key(SDL_KeyboardEvent *ke)
|
||||
void process_key(SDL_Event *e)
|
||||
{
|
||||
uint8_t k=0;
|
||||
|
||||
if ((ke->keysym.sym >= 0x20) && (ke->keysym.sym <= 0x7f)) {
|
||||
k = ke->keysym.sym;
|
||||
// printf("sym=%d mod=%d\n", k, ke->keysym.mod);
|
||||
} else {
|
||||
switch (ke->keysym.sym) {
|
||||
if ((e->type == SDL_TEXTINPUT) && (e->text.text[0] >= 0x20) && (e->text.text[0] <= 0x7f))
|
||||
k = e->text.text[0];
|
||||
else if (e->type == SDL_KEYDOWN) {
|
||||
switch (e->key.keysym.sym) {
|
||||
case SDLK_BACKSPACE:
|
||||
k = 0x10;
|
||||
break;
|
||||
|
@ -196,11 +197,13 @@ void process_key(SDL_KeyboardEvent *ke)
|
|||
break;
|
||||
case SDLK_LSHIFT:
|
||||
case SDLK_RSHIFT:
|
||||
k = 0x90;
|
||||
if (!ignore_modifiers)
|
||||
k = 0x90;
|
||||
break;
|
||||
case SDLK_LCTRL:
|
||||
case SDLK_RCTRL:
|
||||
k = 0x91;
|
||||
if (!ignore_modifiers)
|
||||
k = 0x91;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
@ -240,8 +243,14 @@ void lem1802_tick()
|
|||
else if (e.key.keysym.sym == SDLK_F11) {
|
||||
update_font();
|
||||
update_palette();
|
||||
} else if (e.key.keysym.sym == SDLK_F10) {
|
||||
ignore_modifiers = !ignore_modifiers;
|
||||
} else
|
||||
process_key(&e.key);
|
||||
process_key(&e);
|
||||
}
|
||||
if (e.type == SDL_TEXTINPUT) {
|
||||
// printf("Text input: %s\n", &e.text.text);
|
||||
process_key(&e);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue