private void timer2_Tick(object sender, EventArgs e) { SendKeys.Send(_deleting ? "{BACKSPACE}" : RandomString(1)); _deleting = !_deleting; if (DateTime.Now - _startTime >= TimeSpan.FromMinutes(30)) { timer2.Enabled = false; } }
/// <summary>发送一个或多个击键到活动窗口,如果在键盘上输入。</summary> /// <param name="keys">一个字符串,定义发送键。</param> /// <param name="wait">可选的。一个布尔值,指定是否等待的应用程序继续之前得到处理的击键。默认为true。</param> /// <filterpriority>1</filterpriority> /// <PermissionSet><IPermission class="System.Security.Permissions.EnvironmentPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" /><IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" /><IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="UnmanagedCode, ControlEvidence" /></PermissionSet> public static void SendKeys(string keys, bool wait) { if (wait) { SendKeysProxy.SendWait(keys); } else { SendKeysProxy.Send(keys); } }
private void spelling_SpeechRecognized(object sender, SpeechRecognizedEventArgs e) { string speech = e.Result.Text; if (speech == "Quit spelling mode") { synth.SpeakAsync("I'm now in dictation mode"); spelling.RecognizeAsyncCancel(); dictMode.RecognizeAsync(RecognizeMode.Multiple); } else if (speech == "new line" || speech == "Enter") { TSendKeys.Send("{ENTER}"); } else if (speech == "backspace") { TSendKeys.Send("{BACKSPACE}"); } else if (speech == "dot") { TSendKeys.Send("."); } else if (speech == "question mark") { TSendKeys.Send("?"); } else if (speech == "space") { TSendKeys.Send(" "); } else if (speech == "comma") { TSendKeys.Send(","); } else { TSendKeys.Send(speech); } }
private void dictMode_SpeechRecognized(object sender, SpeechRecognizedEventArgs e) { string speech = e.Result.Text; if (speech == "Quit dictation mode") { dictMode.RecognizeAsyncCancel(); synth.SpeakAsync("I'm now in normal mode"); _recognizer.RecognizeAsync(RecognizeMode.Multiple); } else if (speech == "Stop listening") { synth.SpeakAsync("If you need me just ask"); dictMode.RecognizeAsyncCancel(); dictModeSleep.RecognizeAsync(RecognizeMode.Multiple); } else if (speech == "spelling mode") { synth.SpeakAsync("I'm now in spelling mode"); dictMode.RecognizeAsyncCancel(); spelling.RecognizeAsync(RecognizeMode.Multiple); } else if (speech == "new line" || speech == "Enter") { TSendKeys.Send("{ENTER}"); } else if (speech == "dot") { TSendKeys.Send("."); } else if (speech == "question mark") { TSendKeys.Send("?"); } else if (speech == "space") { TSendKeys.Send(" "); } else if (speech == "comma") { TSendKeys.Send(","); } else if (speech == "Show commands") { string[] Listeningcommands = (File.ReadAllLines(@"ListeningCommands.txt")); foreach (string Listeningcommand in Listeningcommands) { LstCommands.Items.Add(Listeningcommand); } string[] dictCommands = (File.ReadAllLines(@"DictCommands.txt")); LstCommands.Items.Clear(); LstCommands.SelectionMode = SelectionMode.None; LstCommands.Visible = true; LstCommands.BackColor = SystemColors.Control; LstCommands.Items.Add("\n \n"); foreach (string dictCommand in dictCommands) { LstCommands.Items.Add(dictCommand); } } else if (speech == "Hide commands") { LstCommands.Visible = false; } else if (speech == "Close program") { System.Windows.Forms.Application.Exit(); } else { TSendKeys.Send(speech); } }