console: Format tabs semi-intelligently
[attac-man.git] / input.c
blob1081cc22d9253a7055dac41809a1fb047306f7e7
1 /*
2 Pacman Arena
3 Copyright (C) 2003 Nuno Subtil
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 static const char cvsid[] =
21 "$Id: input.c,v 1.4 2003/11/30 17:43:55 nsubtil Exp $";
23 #ifdef _WIN32
24 #include <windows.h>
25 #endif
27 #include <stdlib.h>
28 #include <string.h>
29 #include <SDL.h>
31 #include "screen.h"
32 #include "oglconsole.h"
34 static char keyboard_map[SDLK_LAST];
36 void input_reset(void)
38 memset(keyboard_map, 0, sizeof(keyboard_map));
42 processes all events and clears the SDL event queue
44 void input_update(void)
46 SDL_Event ev;
48 while(SDL_PollEvent(&ev))
50 if (OGLCONSOLE_SDLEvent(&ev) != 0)
51 continue;
53 if(ev.type == SDL_QUIT)
55 SDL_Quit();
56 exit(0);
59 if(ev.type == SDL_KEYDOWN)
61 keyboard_map[ev.key.keysym.sym] = 1;
63 /* special hooks */
64 if(keyboard_map[SDLK_LALT] && keyboard_map[SDLK_RETURN])
66 screen_toggle_fullscreen();
67 keyboard_map[SDLK_LALT] = 0;
68 keyboard_map[SDLK_RETURN] = 0;
72 if(ev.type == SDL_KEYUP)
73 keyboard_map[ev.key.keysym.sym] = 0;
78 returns the current state of a key
80 int input_kstate(int ksym)
82 if(ksym < 0 || ksym >= SDLK_LAST)
84 printf("input_kstate: invalid ksym %d\n", ksym);
85 SDL_Quit();
86 exit(1);
89 return keyboard_map[ksym];
93 clears a key state
95 void input_kclear(int ksym)
97 if(ksym < 0 || ksym >= SDLK_LAST)
99 printf("input_kclear: invalid ksym %d\n", ksym);
100 SDL_Quit();
101 exit(1);
104 keyboard_map[ksym] = 0;