如何在鼠标移动时检测shift键pressed状态鼠标、状态、如何在、shift

2023-09-03 04:46:37 作者:开黄钻是为了隐藏访问记录

我想显示的图像放大叠加时,鼠标和shift键pressed。

I'm trying to show a zoomed in overlay on an image when mouse over and shift key pressed.

问题是,用户可能有pressed shift键之前甚至窗口具有焦点,所以的KeyDown监测并不是一个解决方案。

The problem is that user might have pressed the shift key before even the window has focus, so KeyDown monitoring is not a solution.

有没有办法在鼠标事件进入修改键的状态? 在Java中,例如鼠标事件包含标志组合键,不是那么.NET。

Is there a way to access modifier key states during mouse events? In Java for example the mouse event contains flags for modifier keys, not so in .NET.

推荐答案

尝试使用Control.ModifierKeys属性:

if ((Control.ModifierKeys & Keys.Shift) != Keys.None)
{
    // do my stuff
}