【发布时间】:2020-02-17 16:48:49
【问题描述】:
我一直在使用下面的代码来显示虚拟屏幕键盘,到目前为止工作良好,直到 10.14,但它不再在 Catalina (10.15) 上工作。在 Catalina 上,它不再能够创建输入源并且它总是空的 -
+ (void) showHideVirtualKeyboard:(BOOL) shouldShow {
NSDictionary *property = [NSDictionary dictionaryWithObject:(NSString*)kTISTypeKeyboardViewer
forKey:(NSString*)kTISPropertyInputSourceType];
NSLog(@"showHideVirtualKeyboard my dictionary is - %@",property);
NSArray *sources = (__bridge NSArray*)TISCreateInputSourceList((__bridge CFDictionaryRef)property, false);
if([sources count] == 0) {
DBLogError(@"ToggleKeyboard: no input keyboard source type found...");
DBLogError(@"ToggleKeyboard: Trying to create keyboard soruce type");
sources = (__bridge NSArray*)TISCreateInputSourceList((__bridge CFDictionaryRef)property, true);
if ([sources count]==0) {
DBLogError(@"ToggleKeyboard: Still can't find any input sources so nothing to...");
if(sources)
CFRelease((CFTypeRef)sources);
return;
}
}
TISInputSourceRef keyboardViewer = (__bridge TISInputSourceRef)[sources objectAtIndex:0];
//DBLogInfo(@"********** received sources are %@",keyboardViewer);
int osStatus;
//let's show hide keyboard
if (shouldShow == YES){
CFBooleanRef enabled = TISGetInputSourceProperty(keyboardViewer, kTISPropertyInputSourceIsEnabled);
if (enabled == kCFBooleanFalse)
TISEnableInputSource(keyboardViewer);
// DBLogInfo(@"kTISPropertyInputSourceIsEnabled = %@",(enabled == kCFBooleanFalse)?@"false":@"true");
osStatus = TISSelectInputSource(keyboardViewer);
}
else
osStatus = TISDeselectInputSource(keyboardViewer);
if(osStatus !=noErr)
DBLogInfo(@"ToggleKeyboard: Received errored OSStatus and it is (%d) ",osStatus);
if(sources)
CFRelease((CFTypeRef)sources);
}
请告知是否有人遇到过类似问题并且有任何解决方案/解决方法可用。
谢谢。
【问题讨论】:
-
似乎 Apple 完全放弃了虚拟键盘,而现在他们只有辅助功能键盘。不确定如何以编程方式提出这一点。
标签: objective-c macos macos-carbon macos-catalina