Fixed makefile.
[bcl.git] / keyboard.c
blob022a0fae92cc56b1914ee5ceac766c306d5980b3
1 #include <string.h>
2 #include <stdlib.h>
3 #include <stdio.h>
4 #include <SDL/SDL.h>
6 Uint8 *oldkeys=NULL;
8 DECLSPEC int isKeyDown(int key) {
9 int num = 0;
10 Uint8 *keystate = SDL_GetKeyState(&num);
11 return keystate[key]? 1:0;
14 DECLSPEC int isKeyPressed(int key) {
15 int num;
16 int ret=0;
17 Uint8 *keystate = SDL_GetKeyState(&num);
18 if (oldkeys==NULL)
19 oldkeys=calloc(num,1);
20 if (keystate[key]&&!oldkeys[key])
21 ret=1;
22 oldkeys[key] = keystate[key];
23 return ret;
26 DECLSPEC int isKeyReleased(int key) {
27 int num;
28 int ret=0;
29 Uint8 *keystate = SDL_GetKeyState(&num);
30 if (oldkeys==NULL)
31 oldkeys=calloc(num,1);
32 if (!keystate[key]&&oldkeys[key])
33 ret=1;
34 oldkeys[key] = keystate[key];
35 return ret;
38 DECLSPEC int getPressedKey() {
39 int i;
40 for (i = 1; i < SDLK_LAST; i++)
41 if (isKeyPressed(i))
42 return i;
43 return 0;
46 DECLSPEC int getReleasedKey() {
47 int i;
48 for (i = 1; i < SDLK_LAST; i++)
49 if (isKeyReleased(i))
50 return i;
51 return 0;
54 DECLSPEC char getPressedChar() {
55 // nead to use the window queue for this
56 char ret;
57 SDL_Event evt;
58 if (!SDL_PollEvent(&evt))
59 return 0;
60 if (evt.type!=SDL_KEYDOWN)
61 return 0;
62 ret = evt.key.keysym.unicode&0x7F;
63 return ret;