VZVirtualMachineView and rightMouseDown

Hi, I am displaying the running linux ubuntu VM in VzVirtualMachineView. I wouldl like to simulate right click by calling vZVirtualMachineView.rightMouseDown to trigger right click on the guest. I tried it and it does not work. For mac os guests it is working. For linux guests it is not working

Any help would be appreciated to fix the issue.

Answered by rbmanian75 in 888358022

Apple asked me to use cgevent like this


guard let cgEvent = CGEvent(mouseEventSource: nil, mouseType: .rightMouseDown, mouseCursorPosition: cgPoint, mouseButton: .right) else {
        return
    }

    // Create the synthetic NSEvent from the CGEvent.
    guard let event = NSEvent(cgEvent: cgEvent) else {
        return
    }

    virtualMachineView.rightMouseDown(with: event)
For mac os guests it is working. For linux guests it is not working

We kinda expect that macOS and Linux would behave the same in this regard, so I’m gonna recommend that you start out by filing a bug about this.

Please post your bug number, just for the record.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Here is the bug number FB22727902

Apple provided solution to this problme via feedback assistant and it worked like a charm.

Would you care to share the explanation? I’m sure other developers would be interested in your experience.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Apple asked me to use cgevent like this


guard let cgEvent = CGEvent(mouseEventSource: nil, mouseType: .rightMouseDown, mouseCursorPosition: cgPoint, mouseButton: .right) else {
        return
    }

    // Create the synthetic NSEvent from the CGEvent.
    guard let event = NSEvent(cgEvent: cgEvent) else {
        return
    }

    virtualMachineView.rightMouseDown(with: event)
VZVirtualMachineView and rightMouseDown
 
 
Q