如何在NSView中模拟鼠标向下/向上/拖动

时间:2014-10-30 15:47:24

标签: ios macos mouse move

我正在寻找一种解决方案,如何在OSX应用程序中模拟鼠标按下/向上/拖动事件。

现在我正在使用此代码:

switch (packetType) {
    case QCPacketTouchStarted:
        evtType = NSLeftMouseDown;
        mouseEvent = [NSEvent mouseEventWithType:evtType
                                        location:point
                                   modifierFlags:nil
                                       timestamp:[NSDate timeIntervalSinceReferenceDate]
                                    windowNumber:self.myView.window.windowNumber
                                         context:[NSGraphicsContext currentContext]
                                     eventNumber:nil
                                      clickCount:1
                                        pressure:1];
        [self.myView mouseDown:mouseEvent];
        break;

    case QCPacketTouchMoved: {
        evtType = NSLeftMouseDragged;
        mouseEvent = [NSEvent mouseEventWithType:evtType
                                        location:point
                                   modifierFlags:nil
                                       timestamp:[NSDate timeIntervalSinceReferenceDate]
                                    windowNumber:self.myView.window.windowNumber
                                         context:[NSGraphicsContext currentContext]
                                     eventNumber:nil
                                      clickCount:1
                                        pressure:1];
        [self.myView mouseDragged:mouseEvent];
    }
        break;

    case QCPacketTouchEnded:
        evtType = NSLeftMouseUp;
        mouseEvent = [NSEvent mouseEventWithType:evtType
                                        location:point
                                   modifierFlags:nil
                                       timestamp:[NSDate timeIntervalSinceReferenceDate]
                                    windowNumber:self.myView.window.windowNumber
                                         context:[NSGraphicsContext currentContext]
                                     eventNumber:nil
                                      clickCount:1
                                        pressure:1];
        [self.myView mouseUp:mouseEvent];
        break;

}

问题是mouseDown和mouseUp事件处理正确(视图是接收点击),但鼠标没有移动mouseDragged事件。我在这里做错了什么?

0 个答案:

没有答案