diff --git a/src/corelib/input.c b/src/corelib/input.c index 571de49..df5c666 100644 --- a/src/corelib/input.c +++ b/src/corelib/input.c @@ -23,7 +23,8 @@ void add_key_listener(SDL_Scancode negative, SDL_Scancode positive, g_key_listeners_endptr->axis.delegate = delegate; g_key_listeners_endptr->axis.positive = positive; g_key_listeners_endptr->axis.negative = negative; - g_key_listeners_endptr->axis.last = 0; + g_key_listeners_endptr->axis.last_positive = + g_key_listeners_endptr->axis.last_negative = 0; ++g_key_listeners_endptr; } @@ -101,13 +102,14 @@ static inline void _handle_key_event(const SDL_Event event) { for(input_listener_t* listener = g_key_listeners; listener < g_key_listeners_endptr; ++listener) { if(listener->type == INPUT_LISTENER_AXIS) { - if(listener->axis.positive == event.key.keysym.scancode - || listener->axis.negative == event.key.keysym.scancode) { - const SDL_Scancode scode = event.key.keysym.scancode; - const int value = (event.type == SDL_KEYDOWN ? 1 : -1) * (scode == listener->axis.negative ? -1 : 1); - listener->axis.last += value; - listener->axis.delegate(listener->axis.last); + const SDL_Scancode scode = event.key.keysym.scancode; + if(listener->axis.positive == scode) { + listener->axis.last_positive = event.key.state == SDL_PRESSED; } + if(listener->axis.negative == scode) { + listener->axis.last_negative = event.key.state == SDL_PRESSED; + } + listener->axis.delegate(listener->axis.last_positive - listener->axis.last_negative); } } } diff --git a/src/corelib/input.h b/src/corelib/input.h index 85d3cc8..9be54d6 100644 --- a/src/corelib/input.h +++ b/src/corelib/input.h @@ -25,7 +25,7 @@ typedef struct input_listener_t { struct { input_axis_delegate_t delegate; SDL_Scancode positive, negative; - int last; + int last_positive, last_negative; } axis; struct { input_mouse_delegate_t delegate;