How can I set the mouse position?

前端 未结 5 1404
谎友^
谎友^ 2021-01-15 03:54

I need to set the position of the mouse on the screen. In some other similar question, it was suggested to use CGDisplayMoveCursorToPoint(CGDirectDisplayID display, CG

5条回答
  •  野的像风
    2021-01-15 04:25

    Swift 3 version of the answer that helped me:

    let pt = CGPoint(x: 100, y: 10)
    
    let moveEvent = CGEvent(mouseEventSource: nil, mouseType: .mouseMoved, 
    mouseCursorPosition: pt, mouseButton: .left)
    
    moveEvent?.post(tap: .cgSessionEventTap)
    

提交回复
热议问题