检测批量中的额外鼠标按钮

时间:2017-06-05 14:44:15

标签: batch-file

我是批量编程的新手,我想知道是否有办法检测批量点击额外鼠标按钮的时间。

1 个答案:

答案 0 :(得分:0)

如果您习惯使用c#,您可以构建一个程序来检测批次本身的鼠标输入和管道输入,即getinput.exe | mybatch.cmd。这不是一件微不足道的事情,但你可能会看到 Aacini 如何实现(在这里使用powershell)Tetris game in a pure Batch file

您可以下载完整的mouse batch menu测试hereinputoutputc中处理(和写入),但主要处理是纯batch

以下代码是批量hibryd,如果它不存在则会创建c# executable。您可以根据需要构建c# code复杂的问题,问题是两个抓取cmd's window input并在批处理文件上处理它。

//>nul 2>nul||@goto :batch_code
/*
:batch_code
@echo off
setlocal

if not exist "%~n0.exe" call :build_the_exe || exit/B

%~n0.exe
endlocal
exit /b 0


:build_the_exe
:: find csc.exe
set "frm=%SystemRoot%\Microsoft.NET\Framework\"
for /f "tokens=* delims=" %%v in ('dir /b /a:d  /o:-n "%SystemRoot%\Microsoft.NET\Framework\v*"') do (
   set netver=%%v
   goto :break_loop
)
:break_loop
set "csc=%frm%%netver%\csc.exe"
:: csc not found
if "%csc%" == "\csc.exe" echo/&echo/Warning: Net Framework Not Found&exit/B 1
::csc found
call %csc% /nologo /out:"%~n0.exe" "%~dpsfnx0" 
exit/B 0
*/


//begin c# code
public class HelloWorld
{
   public static void Main()
   {
      System.Console.WriteLine("Hello, C# World!");
   }
}

另一个例子

//>nul 2>nul||@goto :batch_code
/*
:batch_code
@echo off
setlocal

if not exist "keyTime.exe" call :build_the_exe || exit/B

:: use the newly created exe
<NUL set/p="Press a key (wait 5 seconds) "

keyTime.exe /W 5000
endlocal

exit /b 0


:build_the_exe
:: find csc.exe
set "frm=%SystemRoot%\Microsoft.NET\Framework\"
for /f "tokens=* delims=" %%v in ('dir /b /a:d  /o:-n "%SystemRoot%\Microsoft.NET\Framework\v*"') do (
   set netver=%%v
   goto :break_loop
)
:break_loop
set "csc=%frm%%netver%\csc.exe"
:: csc not found
if "%csc%" == "\csc.exe" echo/&echo/Warning: Net Framework Not Found&exit/B 1
::csc found
call %csc% /nologo /out:"keyTime.exe" "%~dpsfnx0" 
exit/B 0
*/


//begin c# code
using System;

namespace ElZooilogico
{
  public static class choice
  {
// readkey with timeout     
    private static void ReadKeyTimeout(int msecs, char theChar)
    {
      theChar = '\0';
      ConsoleKeyInfo cfi;
      ReadKeyDelegate d = Console.ReadKey;
      IAsyncResult result = d.BeginInvoke(null, null);
      result.AsyncWaitHandle.WaitOne(msecs);
      if ( result.IsCompleted )
      {
        cfi = d.EndInvoke(result);
        theChar = cfi.KeyChar;
      }
    }
    delegate ConsoleKeyInfo ReadKeyDelegate();    
// readkey with timeout

    [STAThread]
    public static int Main(string[] args)
    {
      char myChar='\0'; int wait = 10000;

      for ( int i = 0; i < args.Length; i++ )
      {
        if ( args[i].Equals("/W", StringComparison.OrdinalIgnoreCase) ) { wait = Int32.Parse(args[i + 1]); }
      }

      ReadKeyTimeout(wait, myChar);
      Console.Write(myChar);

      return 0;
    }
  } // class miClass
} // namespace ElZooilogico