Go to the documentation of this file.00001 #include "keyboard.h"
00002
00003 keyboard::Keyboard::Keyboard(void)
00004 {
00005 if (SDL_Init(SDL_INIT_VIDEO) < 0) throw std::runtime_error("Could not init SDL");
00006 SDL_EnableKeyRepeat(0, 0);
00007 SDL_WM_SetCaption("ROS keyboard input", NULL);
00008 window = SDL_SetVideoMode(100, 100, 0, 0);
00009 }
00010
00011 keyboard::Keyboard::~Keyboard(void)
00012 {
00013 SDL_FreeSurface(window);
00014 SDL_Quit();
00015 }
00016
00017 bool keyboard::Keyboard::get_key(bool& new_event, bool& pressed, uint16_t& code, uint16_t& modifiers)
00018 {
00019 new_event = false;
00020
00021 SDL_Event event;
00022 if (SDL_PollEvent(&event)) {
00023 switch(event.type) {
00024 case SDL_KEYUP:
00025 pressed = false;
00026 code = event.key.keysym.sym;
00027 modifiers = event.key.keysym.mod;
00028 new_event = true;
00029 break;
00030 case SDL_KEYDOWN:
00031 pressed = true;
00032 code = event.key.keysym.sym;
00033 modifiers = event.key.keysym.mod;
00034 new_event = true;
00035 break;
00036 case SDL_QUIT:
00037 return false;
00038 break;
00039 }
00040 }
00041 return true;
00042 }
00043