简体   繁体   English

为什么在鼠标移动操作期间修改键的状态没有按预期变化?

[英]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. 在El Capitan上的Parallels 11中使用Windows 10 VM时,如果您在按下鼠标键的Mouse事件中似乎无法检查修改键。

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). 我正在观察鼠标当前是否处于按下状态,Parallels仅在鼠标按钮或其他非修改器键盘键更改状态(或释放其他修改器键,但未按下时)时发送/存储修改器键更改。

So... anyone know how to get around this? 所以...有人知道如何解决这个问题吗? We definitely want to support Parallels. 我们绝对希望支持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! Aaaaah! Problem solved! 问题解决了! It's not a bug per se, but it is caused by Parallels and is something you have to explicitly enable. 它本身不是错误,而是由Parallels引起的,必须明确启用它。

Specifically you have to change your keyboard's setting to 'Optimize for games'. 具体来说,您必须将键盘设置更改为“针对游戏进行优化”。 This tells Parallels to be more verbose with key notification messages. 这告诉Parallels在按键通知消息上更为冗长。

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. 经过数天的测试和尝试,然后通过Parallels提交了错误报告,才发现可以通过设置来控制它。 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. Parallels确实很糟糕。

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 检查鼠标事件期间非修饰键是否处于按下状态 - Check if non-modifier keys are in pressed state during mouse events 标签不使用鼠标事件移动 - Labels don't move using Mouse events 以前的工具提示仍然在鼠标移动,并且不刷新! - previous tooltips remain on mouse move, and don't refresh! 鼠标悬停在网格中具有路径的事件不能按预期工作,wpf - Mouse over events with path in a grid don't work as expected, wpf 为什么我们不能更改 ThreadPool 线程的单元状态,为什么在使用 ShowDialog 时我们不需要消息泵? - Why can't we change apartment state of a ThreadPool thread and why don't we require a messagepump when ShowDialog is used? 为什么它说预期的','但我不明白为什么要使用它 - Why it says expected ',' but i don't see why to use it 我正在尝试使用Mouse事件在Canvas(在WPF应用程序)中的Rectangle中移动,但是它不起作用 - I'm trying to move a Rectangle in a Canvas ( in a WPF app) using the Mouse event but it don't work 为什么静态变量不能在ASP.NET中按预期方式工作? - Why don't static variables work as expected in ASP.NET? 回发后,GridView中RadioButtons的检查状态不会更改 - Checked state of RadioButtons in GridView don't change after postback 为什么我们不能在覆盖 C# 中的方法时更改访问修饰符? - Why can't we change access modifier while overriding methods in C#?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM