【问题标题】:if Right button pressed on console如果在控制台上按下右键
【发布时间】:2020-08-10 21:46:05
【问题描述】:

早上好, 我想知道我的鼠标右键是否被按住。 为此,我想到了 System.Windows.Input.Mouse 但如果我执行以下代码会出现此错误:

        while (true)
        {
            if (Mouse.RightButton == MouseButtonState.Pressed)
            {

            }
        }

错误:非托管异常:System.InvalidOperationException:调用线程必须处于 STA 模式,如名称所要求的那样

是否有替代方案或可以用作控制台的东西? 谢谢

【问题讨论】:

标签: c


【解决方案1】:

尝试在这样的函数中使用它:

private void PressLeftButton(object sender, MouseEventArgs e)
{
    if (e.LeftButton == MouseButtonState.Pressed)
    {
        MessageBox.Show("The Left Mouse Button is pressed");
    }
}

【讨论】:

    猜你喜欢
    • 2013-05-09
    • 2021-01-21
    • 1970-01-01
    • 2018-12-03
    • 1970-01-01
    • 1970-01-01
    • 2015-05-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多