Skip to content
TheChatArchiveThe Chat Archive
gpt-3.5-turbo-0613· openaiHugging Face Suzhen/CodeChat

applescript 获取当前鼠标坐标

  1. User

    applescript 获取当前鼠标坐标

  2. Assistant

    以下是一个获取当前鼠标坐标的 AppleScript 代码:

    tell application "System Events"
        set mousePos to position of mouse  -- 获取鼠标的位置
        set xCoord to item 1 of mousePos
        set yCoord to item 2 of mousePos
        display dialog "当前鼠标坐标为:X = " & xCoord & ", Y = " & yCoord
    end tell
    

    运行这段代码后,会弹出一个对话框显示当前鼠标的坐标,X 坐标和 Y 坐标分别显示在对话框中,如:X = 100, Y = 200。

  3. User

    applescript 获取当前鼠标坐标并点击

  4. Assistant

    以下是一个获取当前鼠标坐标并进行点击的 AppleScript 代码:

    tell application "System Events"
        set mousePos to position of mouse -- 获取鼠标的位置
        set xCoord to item 1 of mousePos
        set yCoord to item 2 of mousePos
        
        -- 点击鼠标
        click at {xCoord, yCoord}
    end tell
    

    运行这段代码后,鼠标会在当前位置进行点击操作。

  5. User

    applescript 获取当前鼠标坐标并用鼠标左键点击

  6. Assistant

    以下是一个获取当前鼠标坐标并使用鼠标左键进行点击的 AppleScript 代码:

    tell application "System Events"
        set mousePos to position of mouse -- 获取鼠标的位置
        set xCoord to item 1 of mousePos
        set yCoord to item 2 of mousePos
        
        -- 模拟鼠标点击
        tell process "System Events"
            click at {xCoord, yCoord} -- 鼠标左键点击
        end tell
    end tell
    

    运行这段代码后,鼠标会在当前位置进行鼠标左键的点击操作。