显示系统键盘Mac应用程序? [英] Display System Keyboard Mac application?
问题描述
如果在我的应用程序中选择了任何文本输入字段,我需要显示系统键盘。我似乎找不到任何资源如何做到这一点。任何提示?
I need to display the system keyboard if any text entry fields are selected with in my app. I can't seem to find any resources on how to do this. Any tips?
编辑:我问这个问题,因为我是一个全屏应用程序,需要根据用户选择显示/隐藏。
I'm asking this question because I'm making a full screen application and need to show/hide based on user selection.
感谢,
Teja
Thanks,
Teja
推荐答案
你不能找到的信息是,它是一个C API,它不在可可。您需要使用的API是文本输入源服务。请尝试此示例:
The reason why you can't find the info is that it's a C API and it's not in Cocoa. The API you need to use is Text Input Sources Services. Try this sample:
#import <Foundation/Foundation.h>
#import <Carbon/Carbon.h>
int main(){
NSAutoreleasePool*pool=[[NSAutoreleasePool alloc] init];
NSDictionary*property=[NSDictionary dictionaryWithObject:(NSString*)kTISTypeKeyboardViewer
forKey:(NSString*)kTISPropertyInputSourceType];
NSArray*tisArray=(NSArray*)TISCreateInputSourceList((CFDictionaryRef)property,NO);
// tisArray usually only contains just one keyboard viewer
// in a rare case the user might have another viewer installed, beware
TISInputSourceRef keyboardViewer=(TISInputSourceRef)[tisArray objectAtIndex:0];
TISSelectInputSource(keyboardViewer);
CFRelease((CFTypeRef)tisArray);
[pool drain];
return 0;
}
这是一个Core Foundation类型的API,所以如果你知道Cocoa的用法是类似; Core Foundation基本上是一个用于 NSObject
的C API。大部分情况下,您可以使用免费桥接功能,请参阅此SO问题。当您在垃圾收集环境中保留/释放它们时,您需要小心。 TIS在10.5中引入;我不知道为什么苹果当时没有介绍它作为一个Cocoa API。
显然他们没有想出处理64bit碳。
It's a Core Foundation-type API, so if you know Cocoa the usage is similar; Core Foundation is basically a C API for NSObject
s. Mostly you can use toll-free bridging, see this SO question. You need to be careful when you retain/release them in a garbage-collected environment. TIS was introduced in 10.5; I don't know why Apple didn't introduce it as a Cocoa API back then.
Apparently they hadn't made up their mind to dispose of 64bit Carbon then.
这篇关于显示系统键盘Mac应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!