Summary
selectedKeyboardInputSource
を実行しても 今
の input source
が取得できない
python
1print( NSTextInputContext().selectedKeyboardInputSource() ) 2# => com.apple.keylayout.US 3 4# ここで US -> Japanese にきりかえる 5 6print( NSTextInputContext().selectedKeyboardInputSource() ) 7# => com.apple.keylayout.US
swift
でも objective-c
でもかまいません。ヒントをいただければ。。。よろしくおねがいします。
実際のコード
python
1from AppKit import NSTextInputContext , NSTextView 2 3def loop(): 4 5 txt = NSTextInputContext.alloc().initWithClient_( NSTextView.new() ) 6 7 while True: 8 if input() == '': 9 break 10 else: 11 print( txt.selectedKeyboardInputSource() ) 12 13loop()
結果
補足
イベントを取得してその後に実行すると、その分はうまくいきます
pyhon
1import Foundation 2from AppKit import NSObject, NSTextInputContext , NSTextView, NSTextInputContextKeyboardSelectionDidChangeNotification 3from PyObjCTools import AppHelper 4import objc 5 6class Observer(NSObject): 7 8 def initWithValue_(self, value): 9 self = objc.super(Observer, self).init() 10 self.text_input_context = NSTextInputContext.alloc().initWithClient_( NSTextView.new() ) 11 self.ivar_value = value 12 return self 13 14 def bundle_(self, aNotification): 15 print( self.text_input_context.selectedKeyboardInputSource() ) 16 17 18obs = Observer.new().initWithValue_('') 19 20notify_obj = Foundation.NSNotificationCenter.defaultCenter() 21 22notify_obj.addObserver_selector_name_object_( 23 obs 24 , 'bundle:' 25 , NSTextInputContextKeyboardSelectionDidChangeNotification 26 , None 27) 28 29AppHelper.runConsoleEventLoop()

あなたの回答
tips
プレビュー