0

I am simulating mouse click with below code taken from here that works. But if I chain mouse click events it does not work after first tap is sent, although thread stays active.

code trying with:

  let position1 = CGPoint(x: 10, y: 100)
  let position = CGPoint(x: 80, y: 300)
  let eventDown = CGEvent(mouseEventSource: src, mouseType: .leftMouseDown, mouseCursorPosition: position1 , mouseButton: .left)
  let eventUp = CGEvent(mouseEventSource: src, mouseType: .leftMouseUp, mouseCursorPosition: position1 , mouseButton: .left)
  let eventDown1 = CGEvent(mouseEventSource: src, mouseType: .leftMouseDown, mouseCursorPosition: position1 , mouseButton: .left)
  let eventUp1 = CGEvent(mouseEventSource: src, mouseType: .leftMouseUp, mouseCursorPosition: position1 , mouseButton: .left)


   
                  eventDown?.post(tap: .cghidEventTap)
   //usleep(500_000)
                  eventUp?.post(tap: .cghidEventTap)
   
   //Then for another eventDown n eventUP posts. But that doesn't work
eventDown1?.post(tap: .cghidEventTap)
eventUp1?.post(tap: .cghidEventTap)

above code works for first event. If I post another event (eg: eventUp1 and eventDown1) that does not work.

How can this second tap work?

This is how I'm testing: I am testing with multiple windows of "TextEdit" app and another app like terminal on top of them placing carefully on exact screen coordinates, then checking if those textEdit windows comes forward.

Rifat
  • 1,700
  • 3
  • 20
  • 51

0 Answers0