簡體   English   中英

添加鍵盤快捷鍵

[英]Add keyboard shortcut

我想為我的家制作小應用程序。 它會自動偵測鍵盤快捷鍵(例如:Cmd的 + C + 1),目前選定的文本發送到我的應用程序(如自動機服務)。

我該怎么做? 也許您可以給我教程鏈接?

我認為您要使用Automator Action 在Xcode中,創建一個Application Plug-in Automator Action並將通知發布到NSDistributedNotificationCenter

- (id)runWithInput:(id)input fromAction:(AMAction *)anAction error:(NSDictionary **)errorInfo
{
    NSDistributedNotificationCenter *dc = [NSDistributedNotificationCenter defaultCenter];
    [dc postNotificationName:@"aName" object:@"anObject"
                    userInfo:[NSDictionary dictionaryWithObject:input
                                                         forKey:@"aKey"]];
    return input;
}

您將需要在您的應用中實現觀察者

[[NSDistributedNotificationCenter defaultCenter] addObserver:self selector:@selector(aSelector:) name:@"aName" object:nil];

如果您在應用程序中包含Automator Action捆綁包,則${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.app/Contents/Library/Automator/ Automator應該可以找到它。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM