the problem im having is to detect a CR , ( "ENTER") from the keyboard to send the text.
The libary has commards for other keys like backspace ect .. but i cant find varible for enter key.
BUT ... it does send enter when i print directly to the serial port.
So im thinking look for the enter byte ?
#define KBD_CLK_PIN 3
#define KBD_DATA_PIN 4
PS2Keyboard keyboard;
void setup() {
keyboard.begin(KBD_DATA_PIN);
Serial.begin(9600);
delay(1000);
}
#define is_printable(c) (!(c&0x80)) // don't print if top bit is set
void loop() {
if(keyboard.available()) {
// reading the "extra" bits is optional
byte extra = keyboard.read_extra(); // must read extra before reading the character byte
byte c = keyboard.read();
if (c==PS2_KC_UP) { // this is the commards for the libary but i cant find one for enter .
Serial.print("up\n"); {
Serial.print(c); // this prints everything to serial port including enter
}
The PS2_ constants are for the non-ascii keys, such as the left and right arrows. The enter key generates an ascii value. It's either 10 or 13 (one is the carriage return, the other is line feed. I can never keep them straight, and I don't have a book handy).
According to the code, it returns a newline character when the enter key is pressed. Your sketch should check for '\n', also known as linefeed, LF, or 0x0a.
As that example shows, you'll need to build a string character by character, then put a NUL character ('\0') after the last character. This makes it a NUL-terminated string, which is what the functions that work with strings expect.
You might also have a look at avr-libc: <string.h>: Strings which shows which functions you have available for manipulating strings.