LoginSignup
12
11

More than 5 years have passed since last update.

アクティブでないアプリの特定アクションをホットキーで実行する

Last updated at Posted at 2012-02-28

アプリケーションがアクティブでない時でもホットキーで特定のアクションを実行させたい場合, https://github.com/davedelong/DDHotKey を使うとすぐ実装できる.使い方は以下.

DDHotKeyCenter *ddhkc = [[DDHotKeyCenter alloc] init];
if (![ddhkc registerHotKeyWithKeyCode:40 modifierFlags:(NSShiftKeyMask|NSCommandKeyMask) target:self action:@selector(someMethod:) object:nil]) {
  NSLog(@"Failed to register hotkey");
}

このコードのうち

  • キーコード
  • モディファイヤキー
  • アクション
  • 渡すオブジェクト

の4つを変更し,これを例えばAppDelegate.m- applicationDidFinishLaunching:aNotificationなどで実行してやればよい.

アプリをアクティブにしたいときは呼ばれるアクションの中で

[NSApp activateIgnoringOtherApps:YES]

を実行する.

参考: https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/ApplicationKit/Classes/NSApplication_Class/Reference/Reference.html#//apple_ref/occ/instm/NSApplication/activateIgnoringOtherApps:

12
11
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
12
11