检测左鼠标按下并按住按钮的时间

时间:2016-06-01 14:55:34

标签: c#

尝试让按钮执行多项功能。当按钮刚刚单击并使用鼠标左键释放时,它将向exe发送命令,然后等待一小段时间并发送相反的命令。我还需要按钮在单击按钮时发送一个命令,然后保持鼠标左键,然后释放鼠标时相反。

到目前为止附件是我的代码,如果我将EventArgs更改为MouseEventArgs,我会得到一个“没有超载'PowerButton_Click'匹配委托'EventHandler'”

提前感谢您的帮助。

    // Toggle Power Button relay
    private void PowerButton_Click(object sender, MouseEventArgs e)
    {
        //If left mouse held when power button clicked then hold relay on

        if (e.Button == MouseButtons.Left)
        {
            Process controlusb = new Process();
            controlusb.StartInfo = new ProcessStartInfo("C:\\CommandApp.exe");
            controlusb.StartInfo.Arguments = "afEd5 open 01";
            controlusb.StartInfo.UseShellExecute = false;
            controlusb.StartInfo.LoadUserProfile = true;
            controlusb.StartInfo.RedirectStandardInput = true;
            controlusb.StartInfo.RedirectStandardOutput = true;
            controlusb.StartInfo.RedirectStandardError = true;
            controlusb.Start();
        }
        //else button no longer held then close the relay and handle the button being clicked and released.
        else
        {
            Process controlusb = new Process();
            controlusb.StartInfo = new ProcessStartInfo("C:\\CommandApp.exe");
            controlusb.StartInfo.Arguments = "afEd5 close 01";
            controlusb.StartInfo.UseShellExecute = false;
            controlusb.StartInfo.LoadUserProfile = true;
            controlusb.StartInfo.RedirectStandardInput = true;
            controlusb.StartInfo.RedirectStandardOutput = true;
            controlusb.StartInfo.RedirectStandardError = true;
            controlusb.Start();

            controlusb.StartInfo = new ProcessStartInfo("C:\\CommandApp.exe");
            controlusb.StartInfo.Arguments = "afEd5 open 01";
            controlusb.StartInfo.UseShellExecute = false;
            controlusb.StartInfo.LoadUserProfile = true;
            controlusb.StartInfo.RedirectStandardInput = true;
            controlusb.StartInfo.RedirectStandardOutput = true;
            controlusb.StartInfo.RedirectStandardError = true;
            controlusb.Start();
            Thread.Sleep(100);
            controlusb.StartInfo = new ProcessStartInfo("C:\\CommandApp.exe");
            controlusb.StartInfo.Arguments = "afEd5 close 01";
            controlusb.StartInfo.UseShellExecute = false;
            controlusb.StartInfo.LoadUserProfile = true;
            controlusb.StartInfo.RedirectStandardInput = true;
            controlusb.StartInfo.RedirectStandardOutput = true;
            controlusb.StartInfo.RedirectStandardError = true;
            controlusb.Start();
        }

    }

0 个答案:

没有答案