押されたマウスボタンとポインターの位置をリアルタイムで得る [AppleScript辞書はつくれるか?]
script AppDelegate property parent : class "NSObject" property theWindow : missing value global updateTimer global textField1, textField2 global meinScreenWidth, meinScreenHeight
on applicationWillFinishLaunching_(aNotification) set theSize to current application's NSMakeSize(380,150) theWindow's setContentSize_(theSize) theWindow's setTitle_("マウス実験")
set theScreen to current application's class "NSScreen"'s screens() set {meinScreenWidth, meinScreenHeight} to ¬ item 2 of ((item 1 of theScreen)'s frame())
set theRect to current application's NSMakeRect(10, 70, 80, 25) set textField0 to current application's class "NSTextField"'s ¬ alloc()'s initWithFrame_(theRect) tell textField0 setEditable_(false) setBordered_(false) setDrawsBackground_(false) setStringValue_("Button No") setFont_(current application's class "NSFont"'s systemFontOfSize_(12.0)) end tell theWindow's contentView()'s addSubview_(textField0)
set theRect to current application's NSMakeRect(20, 50, 50, 25) set textField1 to current application's class "NSTextField"'s ¬ alloc()'s initWithFrame_(theRect) tell textField1 setEditable_(true) setBordered_(true) setDrawsBackground_(true) setStringValue_("-") setFont_(current application's class "NSFont"'s systemFontOfSize_(14.0)) end tell theWindow's contentView()'s addSubview_(textField1)
set theRect to current application's NSMakeRect(95, 70, 250, 25) set textField0 to current application's class "NSTextField"'s ¬ alloc()'s initWithFrame_(theRect) tell textField0 setEditable_(false) setBordered_(false) setDrawsBackground_(false) setStringValue_("mouse location") setFont_(current application's class "NSFont"'s systemFontOfSize_(12.0)) end tell theWindow's contentView()'s addSubview_(textField0)
set theRect to current application's NSMakeRect(100, 50, 250, 25) set textField2 to current application's class "NSTextField"'s ¬ alloc()'s initWithFrame_(theRect) tell textField2 setEditable_(true) setBordered_(true) setDrawsBackground_(true) setStringValue_("-") setFont_(current application's class "NSFont"'s systemFontOfSize_(14.0)) end tell theWindow's contentView()'s addSubview_(textField2)
set updateTimer to current application's class "NSTimer"'s ¬ scheduledTimerWithTimeInterval_target_selector_userInfo_repeats_¬ (0.1, me, "selector1:", missing value, true) end applicationWillFinishLaunching_
on selector1_(sender) set mouseButton to current application's class "NSEvent"'s pressedMouseButtons() textField1's setStringValue_(mouseButton) set mouseLocation to current application's class "NSEvent"'s mouseLocation() set {mouseX, mouseY} to {(mouseLocation's x) as integer, ¬ (meinScreenHeight - (mouseLocation's y) as integer)} set ans to "x,y = " & mouseX & "," & mouseY textField2's setStringValue_(ans) end selector1_
on applicationShouldTerminateAfterLastWindowClosed_(sender) return true end applicationShouldTerminateAfterLastWindowClosed_ on applicationShouldTerminate_(sender) return current application's NSTerminateNow end applicationShouldTerminate_ end script |
コメント 0