的右值初始化NSEvent *類型的參數。我正在嘗試監視用戶在可可應用中按下的按鍵。無法使用類型爲void
我用這個代碼:
// this code works!
CGEventMask keyboardMaskKeyDown = CGEventMaskBit(kCGEventKeyDown);
keyboardEventresult = [NSEvent addGlobalMonitorForEventsMatchingMask:keyboardMaskKeyDown handler:^(NSEvent *keyboardEvent)
{
keyboardEventresult = keyboardEvent;
_currentKeystr = [NSString stringWithFormat:@"%c",[[keyboardEvent characters]characterAtIndex:0]];
NSLog(@"Pressed key: %@",_currentKeystr);
[hiddentextfield setStringValue:[NSString stringWithFormat:@"%@",_currentKeystr]];
}];
但問題是,當我改變:
addGlobalMonitorForEventsMatchingMask
到
addLocalMonitorForEventsMatchingMask
我收到一個錯誤說Cannot initialize a parameter of type NSEvent *(^)(NSEvent *_strong) with an rvalue of type void(^)(NSEvent *_strong)
Here你可以看到,蘋果正在做類似的
_eventMonitor = [NSEvent addLocalMonitorForEventsMatchingMask:
(NSLeftMouseDownMask | NSRightMouseDownMask | NSOtherMouseDownMask | NSKeyDownMask)
handler:^(NSEvent *incomingEvent)
關於如何解決此問題的任何想法的東西嗎?
謝謝,沒有注意到它:) – Jona