So wiring up the keyboard and reading using the
PS/2 Keyboard Library was dead simple, but now I'd like to do something a little different. As it is now, when you press down a key, it performs like a usual keyboard, printing it's respective letter. When you hold it down, it prints the letter over and over, like thisssssssssssss. I would like instead to simply read when the key is pressed and when it is released.
Here's what I've got right now (hacked from the example supplied with the library).
void loop() {
if (keyboard.available()) { //tells if a key is pressed
char c = keyboard.read(); //finds out which key
//Serial.print(c);
if (c == PS2_ESC) { //is it the escape key that is pressed?
if (current_key != 1) { //have we already established that it is pressed?
current_key = 1; //set key as "on"
Serial.print("[ESC ON]");
}
}
}else{
if (current_key != 0) {
current_key = 0; //set key as "off"
Serial.print("[ESC OFF]");
}
}
}
But when I hold a key, it just repeats "[ESC ON][ESC OFF]" over and over again. Am I to deduce that keyboard.available() is only detecting a key press every other loop? If this is the case, is there a way to set up a delay so that they will be in sync? Or better yet, an easy way to fix this in the library files? Any thoughts would be much appreciated.