flame icon indicating copy to clipboard operation
flame copied to clipboard

Only register mouse scroll when key is held down?

Open Mythar opened this issue 1 year ago • 5 comments

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?

Mythar avatar May 12 '24 10:05 Mythar

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. :)

spydon avatar May 13 '24 03:05 spydon

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(); } }

Mythar avatar May 13 '24 12:05 Mythar

I just upgraded to 1.18.0 but i do not see any change on the PointerScaleEvent ?

Mythar avatar Jun 16 '24 12:06 Mythar

I just upgraded to 1.18.0 but i do not see any change on the PointerScaleEvent ?

I must have accidentally closed this, nobody has worked on it. Do you want to submit a PR with your fix?

spydon avatar Jun 16 '24 12:06 spydon

Ah, re-read the issue, I don't think we should listen to scale events in the scroll detector. You should just add a detector for scaling too to your game instead.

spydon avatar Jun 16 '24 12:06 spydon