// -----------------------------------------------------------------------------
// input.cpp
// -----------------------------------------------------------------------------
// Implementation of the keyboard helpers. Edge detection works by draining
// the key state: the caller keeps calling WasKeyPressed(), which internally
// blocks until the key is released again before returning true.
// -----------------------------------------------------------------------------

#include "input.h"

#include <windows.h>

namespace util {

bool IsKeyDown(int virtualKey)
{
	return (GetAsyncKeyState(virtualKey) & 0x8000) != 0;
}

bool WasKeyPressed(int virtualKey)
{
	if (!IsKeyDown(virtualKey))
		return false;

	while (IsKeyDown(virtualKey))
		Sleep(10);

	return true;
}

} // namespace util