1
0
mirror of https://github.com/pevans/erc-c.git synced 2024-06-30 14:29:27 +00:00
erc-c/src/vm_event.c

67 lines
1.5 KiB
C
Raw Normal View History

/*
* vm_event.c
*/
#include "vm_event.h"
2018-02-06 03:43:02 +00:00
/*
* Look through all of the events that are queued up and, whatever we
* need to do for them, do that.
*/
void
vm_event_poll(vm_screen *scr)
{
vm_event ev;
ev.screen = scr;
while (SDL_PollEvent(&ev.event)) {
if (ev.event.type == SDL_KEYDOWN || ev.event.type == SDL_KEYUP) {
vm_event_keyboard(&ev);
}
}
}
2018-02-06 03:43:02 +00:00
/*
* Handle any keyboard events from the event queue. Those would be
* things like pressing a key, releasing a key... boring stuff, really.
*/
void
vm_event_keyboard(vm_event *ev)
{
char ch;
// The sym field is of type SDL_Keycode; this type, however,
// maps roughly to Unicode, which of course maps roughly to
// ASCII in the low range.
ch = (char)ev->event.key.keysym.sym;
// If we had shift pressed, we need to uppercase the
// character.
if (ev->event.key.keysym.mod & KMOD_LSHIFT ||
ev->event.key.keysym.mod & KMOD_RSHIFT
) {
ch = toupper(ch);
}
switch (ev->event.type) {
case SDL_KEYDOWN:
ev->screen->dirty = true;
ev->screen->key_pressed = true;
ev->screen->last_key = ch;
break;
case SDL_KEYUP:
// Note we do not erase the last_key value.
ev->screen->key_pressed = false;
if (ch == SDLK_ESCAPE) {
2018-02-05 06:35:04 +00:00
ev->screen->should_exit = true;
}
break;
default:
break;
}
}