#include "keyboard.h"

/* Updates the keyboard. */
void
keyboard_update(Keyboard* self)
{
	const u8* state;

	memcpy(&self->previous, &self->current, sizeof(u8) * KEYBOARD_KEY_COUNT);
	memset(&self->current, '\0', sizeof(u8) * KEYBOARD_KEY_COUNT);

	state = SDL_GetKeyboardState(NULL);

	memcpy(&self->current, state, KEYBOARD_KEY_COUNT);
}

/* Is the given key pressed? */
bool
keyboard_press(Keyboard* self, KeyboardKeyType type)
{
	return (self->current[type] && !self->previous[type]);
}

/* Is the given key held? */
bool
keyboard_held(Keyboard* self, KeyboardKeyType type)
{
	return (self->current[type] && self->previous[type]);
}

/* Is the given key released? */
bool
keyboard_release(Keyboard* self, KeyboardKeyType type)
{
	return (!self->current[type] && self->previous[type]);
}
