#include "include.h"


Keyboard * Keyboard::instance = 0;

Keyboard * Keyboard::getInstance() {
	if (!instance) {
		instance = new Keyboard();
	}
	return instance;
}

Keyboard::Keyboard() : keys(8), specials(8) {
	for (unsigned int i=0; i < this->keys.size(); i++) {
		this->keys[i] = 0;
	}
	for (unsigned int i=0; i < this->specials.size(); i++) {
		this->specials[i] = 0;
	}
}

bool Keyboard::isKeyDown(unsigned char key) {
	return this->keys[key >> 5] & (1 << (key & 31));
}

void Keyboard::keyDown(unsigned char key) {
	this->keys[key >> 5] |= (1 << (key & 31));
}

void Keyboard::keyUp(unsigned char key) {
	this->keys[key >> 5] &= ~(1 << (key & 31));
}

bool Keyboard::isSpecialDown(int key) {
	return this->specials[(key & 127) >> 5] & (1 << (key & 31));
}

void Keyboard::specialDown(int key) {
	this->specials[(key & 127) >> 5] |= (1 << (key & 31));
}

void Keyboard::specialUp(int key) {
	this->specials[(key & 127) >> 5] &= ~(1 << (key & 31));
}
