Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only register mouse scroll when key is held down? #3155

Closed
1 task
Mythar opened this issue May 12, 2024 · 2 comments
Closed
1 task

Only register mouse scroll when key is held down? #3155

Mythar opened this issue May 12, 2024 · 2 comments

Comments

@Mythar
Copy link

Mythar commented May 12, 2024

What could be improved

I want to detect if CTRL key is pressed while using the mouse wheel (for zooming)

Why should this be improved

I tried to do this using the "KeyboardEvents" and also tried overriding the GameWidget's focusNode.
When any key is down - the onScroll event (ScrollDetector) is never called.

Risks

No response

More information

No response

Other

  • Are you interested in working on a PR for this?
@spydon
Copy link
Member

spydon commented May 13, 2024

I don't think this is related to Flame, it can most likely be reproduced in pure Flutter. You could try reproducing it in Flutter and look on the Flutter issue tracker to see if you can find something about it there. If you do find something, please add it to this issue. :)

@Mythar
Copy link
Author

Mythar commented May 13, 2024

Think i found the solution.
In the gesture_detector_builder.dart : applyMouseDetectors

onPointerSignal : Check for both PointerScrollEvent AND PointerScaleEvent

Test:
_TransformedPointerScrollEvent#2d5e3(position: Offset(719.0, 402.0), scrollDelta: Offset(-0.0, -100.0))
_TransformedPointerScaleEvent#f1527(position: Offset(719.0, 402.0))

EDIT: You could add:
void onScale(PointerScrollInfo info) {} to the ScrollDetector

If you are building for web only:

window.document.onMouseWheel.listen((event) => handleMouseWheelWeb(event));

void handleMouseWheelWeb(dynamic event) {
if (event.ctrlKey) {
event.preventDefault();
}
}

@spydon spydon closed this as completed May 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants