2

PointerWheelChanged我在 WinRT 使用事件检测鼠标滚轮滚动。我PointerPoint.Properties.MouseWheelDelta用来检测滚动的数量和方向:

PointerPoint mousePosition = e.GetCurrentPoint(_control);
var delta = mousePosition.Properties.MouseWheelDelta;

现在有一些设备可以模拟鼠标滚动(触摸板或触摸鼠标等)。他们倾向于PointerWheelChanged每个“滚动”发布数十或数百(原文如此!)事件。旧版鼠标滚轮每点击一次鼠标滚轮就会发出一个事件,其增量为 +-120 个单位。

一旦用户滚动到某个位置,我需要进行一些繁重的处理。

有没有办法理解“新”卷轴已经完成?

仅供参考,这是使用 Microsoft TouchMouse 单指轻弹的鼠标滚轮增量(对不起数量,我只是想说明问题)。

15 15 164 164 304 304 658 658 773 773 887 887 1000 1000 1111 1111 1221 1221 1330 1330 108 108 107 107 106 106 105 105 104 104 103 103 102 102 203 203 100 100 99 99 98 98 97 97 96 96 95 95 94 94 93 93 92 92 91 91 90 90 89 89 88 88 88 88 87 87 86 86 85 85 84 84 83 83 82 82 82 82 81 81 80 80 79 79 78 78 78 78 77 77 76 76 75 75 75 75 74 74 73 73 72 72 72 72 71 71 70 70 70 70 69 69 68 68 67 67 67 67 66 66 65 65 65 65 64 64 63 63 63 63 62 62 62 62 61 61 60 60 60 60 59 59 59 59 58 58 57 57 57 57 56 56 56 56 55 55 55 55 54 54 54 54 53 53 52 52 52 52 51 51 51 51 50 50 50 50 49 49 49 49 48 48 48 48 47 47 47 47 46 46 46 46 46 46 45 45 45 45 44 44 44 44 43 43 43 43 42 42 42 42 42 42 41 41 41 41 40 40 40 40 40 40 39 39 39 39 38 38 38 38 38 38 37 37 37 37 37 37 36 36 36 36 35 35 35 35 35 35 34 34 34 34 34 34 33 33 33 33 33 33 32 32 32 32 32 32 31 31 31 31 31 3130 30 30 30 30 30 30 30 30 29 29 29 29 29 29 29 29 28 28 28 28 28 28 28 28 28 27 27 27 27 27 27 27 27 27 26 26 26 26 26 26 26 26 26 26 26 26 26 26 26 26 26 26 26 26 26 25 25 25 25 25 25 25 25 25 25 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 23 23 23 23 23 23 23 23 23 22 22 22 22 22 22 22 22 22 21 21 21 21 21 21 21 21 21 20 20 20 20 20 20 20 20 20 20 20 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 19 18 18 18 18 18 18 18 18 18 18 18 18 18 18 17 17 17 17 17 17 17 17 17 17 17 17 17 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 15 15 22 22 7 7 7 7 14 14 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 6 6 6 66 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 8 8 12 12 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 9 9 3 3 3 3 3 3 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2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 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1

编辑:现在我做了这个黑客,但它远非完美

// interval between mouse deltas
private readonly TimeSpan _wheelDeltaThrottleInterval = TimeSpan.FromMilliseconds(8);

// interval to wait until scroll is complete
private readonly TimeSpan _wheelDeltaCompleteInterval = TimeSpan.FromMilliseconds(600);

// create smart wheel handler
IObservable<PointerPoint> pointerWheelObservable = 
    System.Reactive.Linq.Observable
        .FromEventPattern<PointerEventHandler, PointerRoutedEventArgs>(
            handler => _control.PointerWheelChanged += handler,
            handler => _control.PointerWheelChanged -= handler)
        .Select(eventPattern =>
            {
                PointerRoutedEventArgs e = eventPattern.EventArgs;
                PointerPoint mousePosition = e.GetCurrentPoint(_control);
                return mousePosition;
            })
        .Where(mousePosition => Math.Abs(mousePosition.Properties.MouseWheelDelta) > MouseWheelDeltaThreshold);

// subscribe to wheel changes
pointerWheelObservable
    .Throttle(_wheelDeltaThrottleInterval)
    .ObserveOnDispatcher()
    .Subscribe(
        OnPointerWheelChanged,
        Logger.TrackException);

pointerWheelObservable
    .Throttle(_wheelDeltaCompleteInterval)
    .Subscribe(
        OnPointerWheelCompleted,
        Logger.TrackException);

EDIT2GestureRecognizer类没有帮助

请参阅这篇关于 Windws 8 操作处理的精彩博客文章。 http://blogs.msdn.com/b/windowsappdev/archive/2012/07/02/modernizing-input-in-windows-8.aspx

不幸的是,经过我的实验,我看到GestureRecognizer无法检测到鼠标滚轮事件洪水已经结束。它在每次调用 .ProcessMouseWheelEvent() 后触发 ManipulationCompleted 事件

4

2 回答 2

1

Use GestureRecognizer for a better low level detection of manipulations including mouse whell. All inputs (mouse, touch, pen, etc.) are included here and supported better than traditional manipulation events. (they don't support single touch rotation, mouse scroller, etc.)

http://code.msdn.microsoft.com/windowsapps/Input-Windows-8-gestures-62c6689b#content

This is much more efficient, flexible and safer than implementing everything from scratch.

于 2013-01-05T11:51:40.220 回答
1

您可以在 WheelChangedEvent 上使用 Reactive Extension 库和节流阀,这样您将始终获得指定节流时间段的最后通知

于 2012-12-11T09:05:10.440 回答