Advertisement
Guest User

LetterSwap

a guest
Dec 30th, 2013
388
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.23 KB | None | 0 0
  1. //
  2. //  main.m
  3. //  LettersSwap
  4. //
  5. //  Created by Dmitrijs Izotovs on 28/10/2013.
  6. //  Copyright (c) 2013 Dmitrijs Izotovs. All rights reserved.
  7. //
  8.  
  9. #import <Cocoa/Cocoa.h>
  10.  
  11. CGEventRef myCGEventCallback(CGEventTapProxy proxy, CGEventType type, CGEventRef event, void *refcon) {
  12.     //0x0b is the virtual keycode for "b"
  13.     //0x09 is the virtual keycode for "v"
  14.     if (CGEventGetIntegerValueField(event, kCGKeyboardEventKeycode) == 0x0B) {
  15.         CGEventSetIntegerValueField(event, kCGKeyboardEventKeycode, 0x09);
  16.     }
  17.    
  18.     return event;
  19. }
  20.  
  21. int main(int argc, char *argv[]) {
  22.    
  23.     CFRunLoopSourceRef runLoopSource;
  24.    
  25.     CFMachPortRef eventTap = CGEventTapCreate(kCGHIDEventTap, kCGHeadInsertEventTap, kCGEventTapOptionDefault, kCGEventMaskForAllEvents, myCGEventCallback, NULL);
  26.    
  27.     if (!eventTap) {
  28.         NSLog(@"Couldn't create event tap!");
  29.         exit(1);
  30.     }
  31.    
  32.     runLoopSource = CFMachPortCreateRunLoopSource(kCFAllocatorDefault, eventTap, 0);
  33.    
  34.     CFRunLoopAddSource(CFRunLoopGetCurrent(), runLoopSource, kCFRunLoopCommonModes);
  35.    
  36.     CGEventTapEnable(eventTap, true);
  37.    
  38.     CFRunLoopRun();
  39.    
  40.     CFRelease(eventTap);
  41.     CFRelease(runLoopSource);
  42.    
  43.    
  44.     exit(0);
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement