diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/crepe/api/Script.cpp | 8 | ||||
| -rw-r--r-- | src/crepe/api/Script.h | 8 | 
2 files changed, 16 insertions, 0 deletions
| diff --git a/src/crepe/api/Script.cpp b/src/crepe/api/Script.cpp index 638cca7..4cd59a5 100644 --- a/src/crepe/api/Script.cpp +++ b/src/crepe/api/Script.cpp @@ -30,3 +30,11 @@ const keyboard_state_t & Script::get_keyboard_state() const {  	SDLContext & sdl_context = this->mediator->sdl_context;  	return sdl_context.get_keyboard_state();  } +bool Script::get_key_state(Keycode key) const{ +	try { +		return this->get_keyboard_state().at(key); +	} catch (...) { +		return false; +	} +} + diff --git a/src/crepe/api/Script.h b/src/crepe/api/Script.h index dcecc07..b5d3dd2 100644 --- a/src/crepe/api/Script.h +++ b/src/crepe/api/Script.h @@ -143,6 +143,14 @@ protected:  	 *   	 */  	const keyboard_state_t & get_keyboard_state() const; +	/** +	 * \brief Utility function to retrieve a single key state. +	 * \see SDLContext::get_keyboard_state +	 *  +	 * \return Keycode state (true if pressed, false if not pressed). +	 *  +	 */ +	bool get_key_state(Keycode key) const;  	//! \}  private: |