Skip to content

WinUI ScottPlot: How to properly detect keyboard modifiers in custom UserActionResponse (Ctrl+MouseWheel zoom) #4967

@diluculo

Description

@diluculo

ScottPlot Version: 5.0.55
Platform: WinUI 3
Environment: .NET 8

Hi! I'm working on a WinUI application using ScottPlot and have encountered issues that I'd like to address properly using ScottPlot's built-in systems:

I'm trying to create a custom mouse wheel behavior where:

  • Normal mouse wheel: No plot interaction (let parent ScrollViewer handle it)
  • Ctrl + mouse wheel: Plot zoom only

I've created a custom IUserActionResponse but can't get keyboard modifier detection to work properly. The control doesn't receive KeyDown/KeyUp events, so KeyboardState.IsPressed() always returns false.

public class CtrlOnlyMouseWheelZoom : IUserActionResponse
{
    public ResponseInfo Execute(IPlotControl plotControl, IUserAction userInput, KeyboardState keys)
    {
        // This always returns false, even when Ctrl is pressed
        bool isCtrlPressed = keys.IsPressed(StandardKeys.Control);
        
        if (userInput is MouseWheelUp && isCtrlPressed)
        {
            // Handle zoom in
        }
        else if (userInput is MouseWheelDown && isCtrlPressed)
        {
            // Handle zoom out
        }
        
        return ResponseInfo.NoActionRequired;
    }
}

Questions:

  1. Is KeyboardState.IsPressed() the correct way to detect modifiers in UserActionResponse?
  2. Are there any platform-specific issues with keyboard state detection in WinUI?
  3. How does the built-in KeyboardPanAndZoom class detect ZoomModifierKey - should I follow that pattern?

Additional observation:
The built-in KeyboardPanAndZoom also seems to have the same issue with Ctrl key detection - this suggests the keyboard modifier detection might have broader issues in WinUI.

Current workaround:
Using WinUI's PointerWheelChanged with e.KeyModifiers.HasFlag(VirtualKeyModifiers.Control), but I'd prefer to use ScottPlot's interaction system.

Any guidance on the proper approach would be greatly appreciated!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions