当鼠标按钮在 OS 中交换时,鼠标单击事件处理程序是否仍然可以根据单击哪个按钮正常工作?
When the mouse buttons are swapped in the OS, do the mouse click event handlers still work correctly with respect to which button was clicked?
从事 IT 工作,偶尔会遇到左撇子的用户,他们更喜欢用左手使用鼠标,并且经常切换鼠标按钮,使右键变成 "primary" 而不是左键。
这是 Windows 中的配置:
这对具有依赖于特定鼠标按钮的代码的 .NET 应用程序(例如 WPF、Winforms 等)有何影响?
使用 WPF PreviewMouseDown event, for example, MouseButtonEventArgs has a ChangedButton property which yields a MouseButton enum 值。 Left
的描述是 "The left mouse button." 关于 "primary" 或 "secondary" 按钮没有任何说明。
与 Winforms 类似 MouseClick event, there is MouseEventArgs with its Button property yielding a MouseButtons enum; Left
的描述只是 "The left mouse button was pressed.",同样没有提及 "standard" 或 "secondary" 按钮。
事实上,我看到的所有与鼠标及其按钮相关的文档都只是通过按钮在标准鼠标设置中的位置来引用它们。文档的 None 指的是 "primary" 或 "secondary" 鼠标按钮。
.NET 框架是否适当地适应 OS' 按钮配置的变化?或者以下 WPF 和 Winforms 代码会中断吗?
WPF:
void MainWindow_PreviewMouseDown(object sender, MouseButtonEventArgs e)
{
if (e.ChangedButton == MouseButton.Left)
{
// do something where the "standard" mouse
// button must be the one that was clicked.
}
}
Winforms:
private void MainForm_MouseClick(object sender, MouseEventArgs e)
{
if (e.Button == System.Windows.Forms.MouseButtons.Left)
{
// do something where the "standard" mouse
// button must be the one that was clicked.
}
}
通过 运行 一些测试,我确定 .NET 足够智能,可以识别按钮已被交换。
例如,在以下两个使用 WPF 和 Winforms 的测试中,在 Windows 中切换鼠标按钮后,我单击了物理 "right" 鼠标按钮,但是 事件响应表明使用了 "left" 鼠标按钮:
WPF:
Winforms:
因此,尽管 Microsoft 缺少文档,但 Left
实际上指的是 "standard" 鼠标按钮,Right
指的是 "secondary" 鼠标按钮。
从事 IT 工作,偶尔会遇到左撇子的用户,他们更喜欢用左手使用鼠标,并且经常切换鼠标按钮,使右键变成 "primary" 而不是左键。
这是 Windows 中的配置:
这对具有依赖于特定鼠标按钮的代码的 .NET 应用程序(例如 WPF、Winforms 等)有何影响?
使用 WPF PreviewMouseDown event, for example, MouseButtonEventArgs has a ChangedButton property which yields a MouseButton enum 值。 Left
的描述是 "The left mouse button." 关于 "primary" 或 "secondary" 按钮没有任何说明。
与 Winforms 类似 MouseClick event, there is MouseEventArgs with its Button property yielding a MouseButtons enum; Left
的描述只是 "The left mouse button was pressed.",同样没有提及 "standard" 或 "secondary" 按钮。
事实上,我看到的所有与鼠标及其按钮相关的文档都只是通过按钮在标准鼠标设置中的位置来引用它们。文档的 None 指的是 "primary" 或 "secondary" 鼠标按钮。
.NET 框架是否适当地适应 OS' 按钮配置的变化?或者以下 WPF 和 Winforms 代码会中断吗?
WPF:
void MainWindow_PreviewMouseDown(object sender, MouseButtonEventArgs e)
{
if (e.ChangedButton == MouseButton.Left)
{
// do something where the "standard" mouse
// button must be the one that was clicked.
}
}
Winforms:
private void MainForm_MouseClick(object sender, MouseEventArgs e)
{
if (e.Button == System.Windows.Forms.MouseButtons.Left)
{
// do something where the "standard" mouse
// button must be the one that was clicked.
}
}
通过 运行 一些测试,我确定 .NET 足够智能,可以识别按钮已被交换。
例如,在以下两个使用 WPF 和 Winforms 的测试中,在 Windows 中切换鼠标按钮后,我单击了物理 "right" 鼠标按钮,但是 事件响应表明使用了 "left" 鼠标按钮:
WPF:
Winforms:
因此,尽管 Microsoft 缺少文档,但 Left
实际上指的是 "standard" 鼠标按钮,Right
指的是 "secondary" 鼠标按钮。