0

How do we capture mouse events on iPadOS using Swift? EX: Mouse click, scroll, move[x,y position] ,etc..

I 've seen a plenty for macOS but not for iPadOS . Can some one please help throwing some light on how to capture mouse events on iPadOS devices ?The requirement is that I will have to connect mouse to an iPad over bluetooth and I should be able to programatically track the mouse movement, click events and scroll events.

Dávid Pásztor
  • 51,403
  • 9
  • 85
  • 116
  • 1
    Have you read Apple's Pointer Interactions documentation? https://developer.apple.com/documentation/uikit/pointer_interactions based on that it doesn't look like Apple exposes the APIs you're looking for to developers – donnywals Jun 11 '20 at 12:11

1 Answers1

0

Mouse clicks are passed in via touchesBegan as a UITouch with a type of .indirectPointer. Add UIApplicationSupportsIndirectInputEvents to your Info.plist file to receive these.

Mouse scroll can be detected by adding a UIPanGestureRecognizer with allowedTouchTypes set to an empty array, and maybe allowedScrollTypesMask set to .all. The event information is sent to the target and selector you assign to the gesture recognizer, the gesture state stores the trackpad state, and translation(in view: UIView?) provides the scroll offset.

As far as I'm aware mouse position, and therefore mouse move, cannot be captured directly.

BonzaiThePenguin
  • 1,413
  • 13
  • 19