Merge ssh://repo.or.cz/srv/git/bcl
[bcl.git] / keyboard.c
blob6189ea9c4a4a413553f6feacbfb0726bd5d5c44b
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;