0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

「MacOS」プログラムで入力ソースを変更

Last updated at Posted at 2020-12-17

解決したこと

MacOSのアプリケーションを起動する際に、日本語入力モードに変更するという問題でした。

例)
現在は「英語」入力モードで、アプリケーションを起動すると、自動的に「日本語」入力モードに変わります。

入力ソース変更コード

# include <Carbon/Carbon.h> //忘れずに
TISInputSourceRef source = TISCopyCurrentKeyboardInputSource();
    NSString *temp= [NSString stringWithFormat:@"%@",TISGetInputSourceProperty(source,kTISPropertyInputSourceLanguages)];
    //NSLog(@"%@", temp);
    NSRange range= [temp rangeOfString:temp];//現在"ja"であるかどうか
    if(range.location != NSNotFound && range.length != 0) {
         source = TISCopyInputSourceForLanguage ((CFStringRef)@"ja");
         if (source != NULL){
             TISSelectInputSource(source);
         }
    }

最後に

仕事中にこのような要求がありましたので、調べるのは結構時間がかかりました。コードは英語ページから引っ張ってきましたが、どのファイルをインポートするのかと書いてなくて、大変でした。似たような問題にあった方に(笑)

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?