Getting cursor position in Python

后端 未结 11 1150
旧巷少年郎
旧巷少年郎 2020-12-02 22:29

Is it possible to get the overall cursor position in Windows using the standard Python libraries?

11条回答
  •  萌比男神i
    2020-12-02 23:17

    For Mac using native library:

    import Quartz as q
    q.NSEvent.mouseLocation()
    
    #x and y individually
    q.NSEvent.mouseLocation().x
    q.NSEvent.mouseLocation().y
    

    If the Quartz-wrapper is not installed:

    python3 -m pip install -U pyobjc-framework-Quartz
    

    (The question specify Windows, but a lot of Mac users come here because of the title)

提交回复
热议问题