How to: Poll for Mouse Input

Polling for mouse input gives you greater control over when input events are processed. However, if there is a long delay between polls this can increase latency.

Polling shows the accumulated events for deltas, so for raw position and scrolling data it will be the total mouse movement since your app started. To get the delta since the last poll, you must subtract the previous value from the current one.

To poll for mouse input

  1. Get the most recent screen position for the mouse pointer from the CoreWindow.PointerPosition property as shown in the following example.

    C++

     auto pointerPosition = CoreWindow::GetForCurrentThread()->PointerPosition;
     // Process the new position.
    
    
  2. Obtain the delta movement since the last poll as shown in the following example.

    C++

     MouseDelta _previousRawPosition;
     MouseDelta currentDelta;
    
     auto currentRawPosition = MouseDevice::GetForCurrentView()->MouseMovementDelta;
    
     currentDelta.x = currentRawPosition.x - _previousRawPosition.x;
     currentDelta.y = currentRawPosition.y - _previousRawPosition.y;
    
     _previousRawPosition = currentRawPosition;
     // Process delta since last poll.
    
    

See also

Overview

Mouse Input
How to: Process Mouse Input Events
Input Technologies and Devices Overviews

Reference

MouseDevice Class
CoreWindow.PointerPosition Property