From 2e579a3b11b3bb5bb8417686230b16cdd3c74190 Mon Sep 17 00:00:00 2001 From: Ben Date: Thu, 19 Aug 2021 18:16:42 +0100 Subject: [PATCH] keyboard ennit --- Aeon/Input/Input.cpp | 28 +++++++++++++++++++++++++--- Aeon/Input/Input.hpp | 6 ++++-- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/Aeon/Input/Input.cpp b/Aeon/Input/Input.cpp index a0caf68..abac537 100644 --- a/Aeon/Input/Input.cpp +++ b/Aeon/Input/Input.cpp @@ -1,6 +1,8 @@ #include "Aeon/Input/Input.hpp" #include +#include +#include #include "Aeon/Core/Events.hpp" @@ -15,6 +17,10 @@ Input::Input() mDisplayEventDispatcher.RegisterAsSource( "ENGINE_DISPLAY_CORE" ); mMouseEventDispatcher.RegisterAsSource( "ENGINE_INPUT_MOUSE" ); mKeyboardEventDispatcher.RegisterAsSource( "ENGINE_INPUT_KEYBOARD" ); + + mKbdState = static_cast(SDL_GetKeyboardState( &numScancodes )); + mOldKbdState = static_cast(malloc( numScancodes / sizeof( uint8_t ) )); + memcpy( mOldKbdState, mKbdState, 242 / sizeof( uint8_t ) ); } Input::~Input() @@ -22,10 +28,13 @@ Input::~Input() mDisplayEventDispatcher.DeRegisterAsSource( "ENGINE_DISPLAY_CORE" ); mMouseEventDispatcher.DeRegisterAsSource( "ENGINE_INPUT_MOUSE" ); mKeyboardEventDispatcher.DeRegisterAsSource( "ENGINE_INPUT_KEYBOARD" ); + + free( mOldKbdState ); } void Input::PollInput() { + SDL_PumpEvents(); while ( SDL_PollEvent( &mEvent ) ) { switch ( mEvent.type ) @@ -54,9 +63,22 @@ void Input::PollInput() } } - //Uint8* state = (Uint8*)SDL_GetKeyboardState( NULL ); - //std::cout << state << std::endl; - //std::cout << std::endl; + // just in case + mKbdState = static_cast(SDL_GetKeyboardState( &numScancodes )); + + // keyboard processing + + // first we want to check if any key has changed + // if a key has changed, then we want to check if any keys are pressed + // if a key is pressed we want to check the keys and dispatch events + // according to the scancode + // keydown and keyup will be done seperately + if ( !std::equal( mKbdState, mKbdState + numScancodes, mOldKbdState ) ) + { + std::cout << "keyboard ennit" << std::endl; + } + + memcpy( mOldKbdState, mKbdState, numScancodes / sizeof( uint8_t ) ); } void Input::mPollDisplay() diff --git a/Aeon/Input/Input.hpp b/Aeon/Input/Input.hpp index 95a47cd..7a60598 100644 --- a/Aeon/Input/Input.hpp +++ b/Aeon/Input/Input.hpp @@ -15,8 +15,8 @@ public: ~Input(); void PollInput(); -private: +private: void mPollDisplay(); void mPollMouse(); void mPollScroll(); @@ -24,8 +24,10 @@ private: void mPollKeyboard(); private: - SDL_Event mEvent; + int numScancodes = 242; + const uint8_t* mKbdState; + uint8_t* mOldKbdState; Aeon::Core::EventDispatcher mDisplayEventDispatcher; Aeon::Core::EventDispatcher mKeyboardEventDispatcher;