#import #import #import #import #import #import #import #import #import "Quasimode.h" #import "JavaScriptQuasimode.h" #import "QuasimodalEventTap.h" @implementation Quasimode - onEvent:(NSNotification *)notification { NSString *type = [[notification userInfo] valueForKey: @"type"]; DOMDocument *document = [[view mainFrame] DOMDocument]; DOMEvent *event = [document createEvent: @"KeyboardEvent"]; DOMKeyboardEvent *keyEvent = (DOMKeyboardEvent *) event; [keyEvent initKeyboardEvent: type canBubble: NO cancelable: NO view: [document defaultView] keyIdentifier: nil keyLocation: 0 ctrlKey: NO altKey: NO shiftKey: NO metaKey: YES altGraphKey: NO]; [document dispatchEvent: event]; } - (id)initWithEventSource:(NSString *)sourceName { if (self = [super init]) { eventSource = [sourceName copy]; [[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(onEvent:) name: @"QuasimodeEvent" object: eventSource]; NSRect rect = {{20, 20}, {100, 100}}; window = [[NSWindow alloc] initWithContentRect: rect styleMask: NSBorderlessWindowMask backing: NSBackingStoreBuffered defer: YES]; view = [[WebView alloc] initWithFrame: rect frameName: nil groupName: nil]; NSURL *url = [NSURL URLWithString: @"http://127.0.0.1:8000"]; NSURLRequest *req = [ NSURLRequest requestWithURL: url cachePolicy: NSURLRequestReloadIgnoringLocalCacheData timeoutInterval: 5 ]; [view setDrawsBackground: NO]; [[[view mainFrame] frameView] setAllowsScrolling: NO]; [[view mainFrame] loadRequest: req]; JSQuasimodeInit(self); [window setOpaque: NO]; [window setBackgroundColor: [NSColor colorWithCalibratedRed: 0.0 green: 0.0 blue: 0.0 alpha: 0.0]]; [window setContentView: view]; [window setLevel: NSScreenSaverWindowLevel]; [window makeKeyAndOrderFront: self]; } return self; } - (NSWindow *)window { return window; } - (WebView *)view { return view; } @end int main(int argc, const char *argv[]) { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; [NSApplication sharedApplication]; QuasimodalEventTap *tap = [[QuasimodalEventTap alloc] initWithName: @"keyboard" quasimodeKey: kCGEventFlagMaskAlternate]; Quasimode *app = [[Quasimode alloc] initWithEventSource: @"keyboard"]; [NSApp run]; return 0; }