[英]Why don't modifier keys' state change as expected during mouse move operations?
想知道是否還有其他人遇到這個問題。 在El Capitan上的Parallels 11中使用Windows 10 VM時,如果您在按下鼠標鍵的Mouse事件中似乎無法檢查修改鍵。
我正在觀察鼠標當前是否處於按下狀態,Parallels僅在鼠標按鈕或其他非修改器鍵盤鍵更改狀態(或釋放其他修改器鍵,但未按下時)時發送/存儲修改器鍵更改。
所以...有人知道如何解決這個問題嗎? 我們絕對希望支持Parallels。 (我也已經向他們提交了一個錯誤,因為這肯定是錯誤的。)
這是代碼。 只需創建一個新項目並將其粘貼到主窗口的代碼中即可。
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);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.