-
Notifications
You must be signed in to change notification settings - Fork 2
/
sdl_kbd.c
88 lines (71 loc) · 1.75 KB
/
sdl_kbd.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/*
* ---------------------------------------------------------------------------
* "THE BEER-WARE LICENSE" (Revision 42, (c) Poul-Henning Kamp): Maxim
* Sobolev <sobomax@altavista.net> wrote this file. As long as you retain
* this notice you can do whatever you want with this stuff. If we meet
* some day, and you think this stuff is worth it, you can buy me a beer in
* return.
*
* Maxim Sobolev
* ---------------------------------------------------------------------------
*/
#include <SDL.h>
#include "def.h"
#include "hardware.h"
#include "sdl_vid.h"
#define KBLEN 30
Sint4 kbuffer[KBLEN];
Sint4 klen=0;
int Handler(const SDL_Event *event)
{
if(event->type == SDL_KEYDOWN) {
if(klen == KBLEN) /* Buffer is full, drop some pieces */
memcpy(kbuffer, kbuffer + 1, --klen);
kbuffer[klen++] = event->key.keysym.sym;
/* ALT + Enter handling (fullscreen/windowed operation) */
if((event->key.keysym.sym == SDLK_RETURN || event->key.keysym.sym == SDLK_KP_ENTER) &&
((event->key.keysym.mod & KMOD_ALT) != 0))
switchmode();
}
if(event->type == SDL_QUIT)
exit(0);
return(1);
}
bool GetAsyncKeyState(int key)
{
Uint8 *keys;
SDL_PumpEvents();
keys = SDL_GetKeyState(NULL);
if (keys[key] == SDL_PRESSED )
return(TRUE);
else
return(FALSE);
}
void initkeyb(void)
{
SDL_EventState(SDL_MOUSEMOTION, SDL_IGNORE);
SDL_EventState(SDL_MOUSEBUTTONDOWN, SDL_IGNORE);
SDL_EventState(SDL_MOUSEBUTTONUP, SDL_IGNORE);
SDL_SetEventFilter(Handler);
}
void restorekeyb(void)
{
}
Sint4 getkey(void)
{
Sint4 result;
while(kbhit() != TRUE)
gethrt();
result = kbuffer[0];
memcpy(kbuffer, kbuffer + 1, --klen);
return(result);
}
bool kbhit(void)
{
SDL_PumpEvents();
doscreenupdate();
if (klen > 0)
return(TRUE);
else
return(FALSE);
}