在 C Sharp 中获取鼠标按钮的状态
Getting the state of a mouse button in C Sharp
我正在用 C sharp 开发一个 Windows 表单项目,我正在寻找一种方法来在单击鼠标右键时调用方法或使用 if 语句来指示是否正在按下鼠标右键
If ([way to get right button state]) StopButton.performClick();
唯一的问题是它需要是通用的,即使用户点击了另一个应用程序(在宏上工作,这应该是停止选项)
我找到的所有解决方案都会检查用户是否点击了应用中的某个位置
-先谢谢了
你可以使用 MouseEventArgs
MouseEventArgs me = (MouseEventArgs) e;
switch (e.Button) {
case MouseButtons.Left:
// Left click
break;
case MouseButtons.Right:
StopButton.performClick();
break;
}
System.Windows.Input.MouseButtonState
public static MouseButtonState LeftButton { get; }
if (Mouse.LeftButton == MouseButtonState.Pressed)
{
Your_function_name("\Do whatever you want");
}
Related Links and Helps:
https://msdn.microsoft.com/en-us/library/system.windows.input.mousebuttoneventargs(v=vs.110).aspx
我正在用 C sharp 开发一个 Windows 表单项目,我正在寻找一种方法来在单击鼠标右键时调用方法或使用 if 语句来指示是否正在按下鼠标右键
If ([way to get right button state]) StopButton.performClick();
唯一的问题是它需要是通用的,即使用户点击了另一个应用程序(在宏上工作,这应该是停止选项)
我找到的所有解决方案都会检查用户是否点击了应用中的某个位置
-先谢谢了
你可以使用 MouseEventArgs
MouseEventArgs me = (MouseEventArgs) e;
switch (e.Button) {
case MouseButtons.Left:
// Left click
break;
case MouseButtons.Right:
StopButton.performClick();
break;
}
System.Windows.Input.MouseButtonState
public static MouseButtonState LeftButton { get; }
if (Mouse.LeftButton == MouseButtonState.Pressed)
{
Your_function_name("\Do whatever you want");
}
Related Links and Helps:
https://msdn.microsoft.com/en-us/library/system.windows.input.mousebuttoneventargs(v=vs.110).aspx