I have been using below code to show the virtual onscreen keyboard and so far working good till 10.14 but it's no longer working on Catalina (10.15). On Catalina it is no longer able to create Input sources and it is always empty -
+ (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);
}
Please advise if anybody has faced similar issue and any solution / workaround is available.
Thanks.