, когда я нажимаю клавишу «вверх» в моем веб-представлении, он регистрирует его, но не запускает предупреждение JS, как определено в stringByEvaluatingJavaScriptFromString
, есть идеи? Спасибо
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
[webView setMainFrameURL:@"http://google.com"];
[webView setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
}
-(id)init {
if( !(self = [super init]) ){
return nil;
}
NSEvent * (^monitorHandler)(NSEvent *);
monitorHandler = ^NSEvent * (NSEvent * theEvent){
switch ([theEvent keyCode]) {
case 123: // Left arrow
NSLog(@"Left behind.");
break;
case 124: // Right arrow
NSLog(@"Right as always!");
break;
case 125: // Down arrow
NSLog(@"Downward is Heavenward");
break;
case 126: // Up arrow
[webView stringByEvaluatingJavaScriptFromString:@"alert('yo')"];
NSLog(@"Up, up, and away!");
break;
default:
break;
}
// Return the event, a new event, or, to stop
// the event from being dispatched, nil
return theEvent;
};
// Creates an object we do not own, but must keep track
// of so that it can be "removed" when we're done
eventMon = [NSEvent addLocalMonitorForEventsMatchingMask:NSKeyDownMask
handler:monitorHandler];
return self;
}