/* $Id: input.cpp,v 1.15 2005/06/28 13:55:19 chfreund Exp $ */ #include "input.hpp" Input::Input() { // check if SDL has been initialized ASSERT( (SDL_WasInit(SDL_INIT_VIDEO ) & SDL_INIT_VIDEO) != 0, "Input::Input: SDL has not been initialized yet\n" ); // disable key repeat SDL_EnableKeyRepeat( 0, 0 ); // disable unicode generation SDL_EnableUNICODE( 0 ); // clear keyboard state array for( int s = 0; s < SDLK_LAST; s++ ) { m_kbState[s] = 0; } } Input::~Input() { } void Input::pumpEvents() { SDL_Event event; while ( SDL_PollEvent( &event ) ) { // Save KEYDOWN and KEYUP events by setting m_kbState if ( event.type == SDL_KEYDOWN ) { m_kbState[event.key.keysym.sym] = JUST_PRESSED; } else if ( event.type == SDL_KEYUP ) { m_kbState[event.key.keysym.sym] = NOT_PRESSED; } // Propagate event to all listeners std::vector::iterator it; for ( it = m_listener.begin(); it != m_listener.end(); it++ ) { if ( (*it)->handleInput( &event ) ) { break; } } } } void Input::setChatMode( bool value ) { if ( value ) { SDL_EnableKeyRepeat( 300, 25 ); SDL_EnableUNICODE( 1 ); } else { SDL_EnableKeyRepeat( 0, 0 ); SDL_EnableUNICODE( 0 ); } } bool Input::anyKeyPressed() { // update(); for( int k = 0; k < SDLK_LAST; k++ ) { if( keyPressed( k )) return true; } return false; }