Skip to content

Flutter should support capturing the mouse pointer #134652

Open

Description

@alexvoina

Is there an existing issue for this?

Use case

I'm trying to implement a "zoom" feature in my app and i really find the one in Ableton Live to have the best feel/UX.

0913.mov

Notice that the mouse cursor disappears on what would be the Flutter Listener's onPointerDown equivalent, and then I can move the mouse as much as I have space on my desk upwards, while normally the cursor would quickly hit the top of my screen.

This is how it looks like in my app. The Listener's onPointerMove is limited by the screen's real estate.

0913.1.mov

Proposal

Any ideas on how I could "hide" the cursor in flutter and count the mouse travelled distance pixels in a virtually infinite space?

Activity

  1. moffatman commented on Sep 13, 2023

    @moffatman
    Contributor

    This would be implementing "mouse cursor capture" on supported desktop platforms. Through some new API I guess. Similar to how a FPS game might want to capture the mouse. No way at all to do it at the moment, let's keep this issue open to track such a feature.

  2. added
    in triagePresently being triaged by the triage team
    c: new featureNothing broken; request for a new capability
    f: gesturesflutter/packages/flutter/gestures repository.
    c: proposalA detailed proposal for a change to Flutter
    frameworkflutter/packages/flutter repository. See also f: labels.
    and removed
    in triagePresently being triaged by the triage team
    on Sep 14, 2023
  3. dkwingsmt commented on Sep 14, 2023

    @dkwingsmt
    Contributor

    Sounds legit. I wonder how mouse events are reported natively when captured? IIRC currently Flutter computes position delta by subtracting positions, so I assume either the position will be unbounded or the position delta will be explicitly given?

  4. 16 remaining items

  5. helgoboss commented on Nov 10, 2023

    @helgoboss

    1st of all, I'm wondering why ShowCursor(0)/ShowCursor(1) (Windows) work when calling them through your plugin, and don't work when calling them from my plugin. Do you have any guess at why that might happen? This is just for my curiosity.

    Not sure, I didn't inspect your code. But one possibility is that it's related to repeated calling. If I understand the Win32 API docs correctly, calling ShowCursor(0) / ShowCursor(1) multiple times will decrement/increment a counter. Windows will show the cursor only if the counter is >= 0. This can also happen with my current implementation if not used correctly. I think will introduce a flag that prevents from calling ShowCursor(0) or ShowCursor(1) again if it already has been called.

    2nd, I'm going to need a few more functions in the API, if I am to completely use your implementation. I need a set of functions to get & set the raw cursor position, because I want to reveal the cursor position based on some custom application logic.

    I have already implemented these partially, so I could make a PR, or just share my code with you. It's pretty much a matter of calling native functions SetCursorPos (Windows) / CGWarpMouseCursorPosition (macOS) and converting from Flutter global coordinate space to native coordinate space.

    Sounds good. Looking forward to the PR.

    I also realized that the pointer locking implementation on Windows has room for improvement. I implemented a knob with it (also for an audio application) and it's way too sensitive.

  6. alexvoina commented on Nov 13, 2023

    @alexvoina
    Author

    alright! thanks for the response, that makes sense. I'm glad to hear I'm not the only one building a desktop audio app with Flutter. I'd be curious to see what you're working on :D

    I'll keep you posted about the PR

  7. flutter-triage-bot commented on Jun 7, 2024

    @flutter-triage-bot

    The triaged-desktop label is irrelevant if there is no team-desktop label or fyi-desktop label.

  8. added
    P3Issues that are less important to the Flutter project
    and removed
    P2Important issues not at the top of the work list
    on Jun 10, 2024
  9. helgoboss commented on Jan 12, 2025

    @helgoboss

    @alexvoina I gave https://github.com/helgoboss/pointer_lock a revamp. It now supports a free mode in which any event can lock or unlock the pointer (see new README). There are a few other improvements as well, such as Linux support (X11), a smaller API surface and a dedicated widget for implementing the popular "lock while drag" use case.

  10. alexvoina commented on Jan 13, 2025

    @alexvoina
    Author

    @helgoboss that's cool! I'll have a look and try to update. Your package still powers my app to this day, making real users happy so thank you for your work!

  11. CodeDoctorDE commented on Jun 26, 2026

    @CodeDoctorDE
    Contributor

    Hi,
    On the windows side it already captures the mouse button if its primary.
    I'm making a contribution to also allow other mouse buttons to be captured on windows: #188394.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3Issues that are less important to the Flutter projectc: new featureNothing broken; request for a new capabilityc: proposalA detailed proposal for a change to Flutterf: gesturesflutter/packages/flutter/gestures repository.frameworkflutter/packages/flutter repository. See also f: labels.team-frameworkOwned by Framework teamtriaged-frameworkTriaged by Framework team

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions