SSブログ

押されたマウスボタンとポインターの位置をリアルタイムで得る [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

image200521a.jpg
Button No は、1:左ボタン、2:右ボタン、0:押されていない となる。
mouse location は、メインの画面の左上角を原点{0,0}として計算している

nice!(0)  コメント(0) 
共通テーマ:パソコン・インターネット

nice! 0

コメント 0

コメントを書く

お名前:
URL:
コメント:
画像認証:
下の画像に表示されている文字を入力してください。

この広告は前回の更新から一定期間経過したブログに表示されています。更新すると自動で解除されます。