Objective c CGEventPostToPSN-如何发送具有不同键盘区域设置的键?
我将按键发送到另一个应用程序,如下所示:Objective c CGEventPostToPSN-如何发送具有不同键盘区域设置的键?,objective-c,xcode,operating-system,Objective C,Xcode,Operating System,我将按键发送到另一个应用程序,如下所示: - (void)keyPress:(int)hotkey withModifier:(unsigned int)modifier withKeyDown:(BOOL)keyDown{ // verify the process still exists ProcessSerialNumber psn = [self myPSN]; CGEventRef keyEvent = NULL; // create our source CGEventSou
- (void)keyPress:(int)hotkey withModifier:(unsigned int)modifier withKeyDown:(BOOL)keyDown{
// verify the process still exists
ProcessSerialNumber psn = [self myPSN];
CGEventRef keyEvent = NULL;
// create our source
CGEventSourceRef source = NULL; // this didn't used to be NULL, does this matter?
if ( source || 1 == 1 ){
keyEvent = CGEventCreateKeyboardEvent(source, (CGKeyCode)hotkey, keyDown);
// set flags for the event (does this even matter? No.)
CGEventSetFlags( keyEvent, modifier );
// hit any specified modifier keys
if ( modifier & NSAlternateKeyMask ){
PostKeyboardEvent( source, kVK_Option, keyDown );
}
if ( modifier & NSShiftKeyMask ){
PostKeyboardEvent( source, kVK_Shift, keyDown );
}
if ( modifier & NSControlKeyMask ){
PostKeyboardEvent( source, kVK_Control, keyDown );
}
if ( modifier & NSCommandKeyMask ){
PostKeyboardEvent( source, kVK_Command, keyDown );
}
// post the actual event
CGEventPostToPSN(&psn, keyEvent);
usleep(30000);
// post it again if we're doing key up, just in case!
if ( !keyDown ){
CGEventPostToPSN(&psn, keyEvent);
}
// release
if ( keyEvent ){
CFRelease(keyEvent);
}
}
}
基本上,如果使用美国键盘,我可以发送键,比如发送:kVK_ANSI_a
问题是对于非美国键盘,如果键盘布局未设置为美国,如何调整这些键以仍能正确发送
以下是我遇到问题的虚拟密钥代码:
提前谢谢 我认为这是与相同的问题