ウインドウ(theWindow)に、ファーストレスポンダを登録して
KeyDownイベントとkeyUpイベントを使う。
script AppDelegate
property parent : class "NSObject"
property theWindow : missing value
on applicationWillFinishLaunching_(aNotification)
theWindow's makeFirstResponder_(me)
end applicationWillFinishLaunching_
on keyUp_(theEvent)
log "key_up"
set a to theEvent's keyCode() --押されているキーボードの仮想コードを取得
log a
set b to theEvent's |characters|() --押されているキーのキャラクター
log b
set c to theEvent's charactersIgnoringModifiers() --Shiftなどの補助キーを無視したキャラクター(?)
log c
end keyUp_
on keyDown_(theEvent)
log "key_down"
set r to theEvent's ARepeat() --キーリピートしているか否かを取得
log r
end keyDown_
on applicationShouldTerminateAfterLastWindowClosed_(sender)
return true
end applicationShouldTerminateAfterLastWindowClosed_
on applicationShouldTerminate_(sender)
return current application's NSTerminateNow
end applicationShouldTerminate_
end script
(*
NSEvent: type=KeyDown--
loc=(-283.68,309.387)
time=13718.2
flags=0x200100
win=0x600003e10400
winNum=810
ctxt=0x0
chars="1"
unmodchars="1"
repeat=1
keyCode=83
*)
|
|
取得はできるのだが、余計なエラーがついてきてしまう。
2018-12-05 14:10:50.360715+0900 test[6907:111147] [General] unable to set argument -1 - the AppleScript value (null) could not be coerced to type c.
2018-12-05 14:10:50.361655+0900 test[6907:111147] [General] (
0 CoreFoundation 0x00007fff2b43efa5 __exceptionPreprocess + 256
1 libobjc.A.dylib 0x00007fff5753aefb objc_exception_throw + 48
...
『unable to set argument -1 - the AppleScript value (null) could not be coerced to type c.』
引き数-1を設定することができません - AppleScriptの値(null)を強制的にタイプcにすることはできませんでした。
AppleScriptObjCの観点からではない。 最大の問題は、スクリプトブリッジが、使用するCスタイルの値の型をサポートしていない。
と、ある。無視したままで良いのだろうか?
コメント 0