os51 发表于 2016-7-30 14:15

【原创源码】[C#] 延时输入

本帖最后由 os51 于 2016-7-30 16:06 编辑

namespace SendKeyWait{
    using System;
    using System.Windows.Forms;

    public class Program
    {
            
      private static void Main(string[] args)
      {
            int timeout = 0;
            try
            {
                x = Convert.ToInt32(args);
                System.Threading.Thread.Sleep(x);
                for (int i = 1; i < args.Length; i++) {SendKeys.SendWait(args.Replace("\r\n", "{ENTER}"));}
            }
            catch
            {
                Environment.Exit(-1);
            }
      }
    }
}

用法: SendKeyWait 300 abcdef
300为延时,单位毫秒

骂人方法:
批处理:for /f "tokens=* eol=; delims=" %%i in (text.txt) do SendKeyWait 500%%i &SendKeyWait 500{ENTER}
命令行直接输入:for /f "tokens=* eol=; delims=" %i in (text.txt) do SendKeyWait 500%i &SendKeyWait 500{ENTER}
text.txt为内容,一行一个

编译:"C:\Windows\Microsoft.NET\Framework\v2.0.50727\csc.exe" SendKeyWait .cs

工藤新二QVQ 发表于 2016-7-30 14:49

谢谢楼主

samjun 发表于 2016-7-31 11:42

没明白这东西有什么用

葬礼昨天 发表于 2016-9-16 10:01

能问一下 这个特性有什么用没吗,一直不是很明白,谢谢

os51 发表于 2016-9-16 14:20

葬礼昨天 发表于 2016-9-16 10:01
能问一下 这个特性有什么用没吗,一直不是很明白,谢谢

The STAThreadAttribute is essentially a requirement for the Windows message pump to communicate with COM components. Although core Windows Forms does not use COM, many components of the OS such as system dialogs do use this technology.

MSDN explains the reason in slightly more detail:

STAThreadAttribute indicates that the COM threading model for the application is single-threaded apartment. This attribute must be present on the entry point of any application that uses Windows Forms; if it is omitted, the Windows components might not work correctly. If the attribute is not present, the application uses the multithreaded apartment model, which is not supported for Windows Forms.
This blog post (Why is STAThread required?) also explains the requirement quite well. If you want a more in-depth view as to how the threading model works at the CLR level, see this MSDN Magazine article from June 2004 (Archived, Apr. 2009).
http://stackoverflow.com/questions/1361033/what-does-stathread-do

葬礼昨天 发表于 2016-9-16 15:15

os51 发表于 2016-9-16 14:20
The STAThreadAttribute is essentially a requirement for the Windows message pump to communicate wi ...

多谢{:301_997:}。。。。。。。。。。。。
页: [1]
查看完整版本: 【原创源码】[C#] 延时输入