如果按下空格键,则触发WPF MouseEnter事件
本文关键字:WPF MouseEnter 事件 空格键 如果 | 更新日期: 2023-09-27 17:49:29
我想处理一个按钮的MouseEnter
事件仅用于鼠标操作。所以我必须检测MouseEnter
是由鼠标还是键盘触发的。
private void button_onMouseEnter(object sender, MouseEventArgs e)
{
Button button = (Button)sender;
if (!button.IsMouseOver) return; // not working
if (!button.IsMouseDirectlyOver) return; // not working
...
}
可以查看最近的输入设备
if (InputManager.Current.MostRecentInputDevice is KeyboardDevice);
如何判断一个按钮点击事件是由键盘或鼠标在WPF触发的?