Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // main.m
- // LettersSwap
- //
- // Created by Dmitrijs Izotovs on 28/10/2013.
- // Copyright (c) 2013 Dmitrijs Izotovs. All rights reserved.
- //
- #import <Cocoa/Cocoa.h>
- CGEventRef myCGEventCallback(CGEventTapProxy proxy, CGEventType type, CGEventRef event, void *refcon) {
- //0x0b is the virtual keycode for "b"
- //0x09 is the virtual keycode for "v"
- if (CGEventGetIntegerValueField(event, kCGKeyboardEventKeycode) == 0x0B) {
- CGEventSetIntegerValueField(event, kCGKeyboardEventKeycode, 0x09);
- }
- return event;
- }
- int main(int argc, char *argv[]) {
- CFRunLoopSourceRef runLoopSource;
- CFMachPortRef eventTap = CGEventTapCreate(kCGHIDEventTap, kCGHeadInsertEventTap, kCGEventTapOptionDefault, kCGEventMaskForAllEvents, myCGEventCallback, NULL);
- if (!eventTap) {
- NSLog(@"Couldn't create event tap!");
- exit(1);
- }
- runLoopSource = CFMachPortCreateRunLoopSource(kCFAllocatorDefault, eventTap, 0);
- CFRunLoopAddSource(CFRunLoopGetCurrent(), runLoopSource, kCFRunLoopCommonModes);
- CGEventTapEnable(eventTap, true);
- CFRunLoopRun();
- CFRelease(eventTap);
- CFRelease(runLoopSource);
- exit(0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement