简体   繁体   中英

Why don't modifier keys' state change as expected during mouse move operations?

Wondering if anyone else is having this issue. While using a Windows 10 VM in Parallels 11 on El Capitan, it seems you can't check the modifier keys if you're in a Mouse event with a mouse key pressed.

I'm observing if the mouse is currently down, Parallels only sends/stores the modifier key changes when a mouse button or different, non-modifier keyboard key changes state (or a different modifier key is released, but not when pressed).

So... anyone know how to get around this? We definitely want to support Parallels. (I've also filed a bug with them about this because it definitely seems wrong.)

Here's the code. Simply create a new project and paste this into the code-behind of the main window.

bool isDragging;

protected override void OnMouseDown(MouseButtonEventArgs e)
{
    if(e.ClickCount == 1 && e.ChangedButton == MouseButton.Left)
    {
        e.Handled = true;
        isDragging = true;
        CaptureMouse();
    }
    base.OnMouseDown(e);
}

protected override void OnMouseMove(MouseEventArgs e)
{
    if(isDragging)
    {
        e.Handled = true;
        Title = "Pressed: " + (Keyboard.Modifiers == ModifierKeys.Shift);
    }
    base.OnMouseMove(e);
}

protected override void OnMouseUp(MouseButtonEventArgs e)
{
    if(isDragging && e.ChangedButton == MouseButton.Left)
    {
        e.Handled = true;
        isDragging = false;
        ReleaseMouseCapture();
    }
    base.OnMouseUp(e);
}

Aaaaah! Problem solved! It's not a bug per se, but it is caused by Parallels and is something you have to explicitly enable.

Specifically you have to change your keyboard's setting to 'Optimize for games'. This tells Parallels to be more verbose with key notification messages.

Why they decided to call it 'Optimize for games' instead of something more informative, or at least better explained what that feature does is beyond me. Days of testing and trying work-arounds followed by a bug report filed with Parallels only to find out it's controllable with a setting. And that's from me, a software architect. I can't even imagine what the non-techie would go through here. Really bad call on the part of Parallels.

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM