Create a timer event that calls Sendkeys.Send(" ")
, then start the timer when you recognize 'space', and stop the timer when you recognize 'stop'.
using System.Threading;
Timer thetimer;
void sRecognize_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
{
if (e.Result.Text.ToString() == "space")
{
theTimer = new Timer(TimerCallback(timeExpired), 500); // 500 ms
}
else // if is stop
{
theTimer.Change(Timeout.Infinite, Timeout.Infinite); // stop the timer
}
}
void timeExpired(Object stateInfo)
{
SendKeys.Send(" ");
}
There are other timer mechanisms you could use as well, but this is pretty straightforward.