Hi Guys

having a bit of trouble here, I have create a form program with a set of buttons which do stuff (open,exit etc). I also got a speech recongtion which has a set of words ive put into a grammar list.

the problem:

i want to the program to click on a particular button when the user says a certain word i.e. user says "start" the start button is clicked! Im using a switch case as well for each different button.

the only thing i think im missing is the code for just automatically clicking the button!

thanks!

i have "" public void button1_Click(object sender, EventArgs e) "" // start button

then

private void voiceCommands()
        {
            eng = new SpeechRecognitionEngine();
            eng.SetInputToDefaultAudioDevice();
            eng.SpeechRecognized += (s, args) =>
                {

                    string line = "";
                    foreach (RecognizedWordUnit word in args.Result.Words)
                    {
                        if (word.Confidence > 0.5f)
                            line += word.Text + " ";
                    }
                    string command = line.Trim();
                    //Button button = new Button();
                    switch (command)
                    {
                        case "Start":
                                (here is want to click the button"
                            break;
                    }
                    richTextBox1.Text += line;
                    richTextBox1.Text += Environment.NewLine;
                };
            eng.UnloadAllGrammars();
            eng.LoadGrammar(words());
            eng.RecognizeAsync(RecognizeMode.Multiple);

        } // Voices commands

        private Grammar words()
        {
            Choices options = new Choices("Start");
            GrammarBuilder build = new GrammarBuilder();
            build.Append(options);
            return new Grammar(build);
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            voiceCommands();
        }

Just add a call to the button click handler. If you don't use the sender or eventargs you can just pass null, null to it.

got it to work, I ended up using ""this.BeginInvoke(new MethodInvoker(delegate() { button1.PerformClick(); }));""

thanks

Do you want it to actually animate as if it were clicked (mouse moves, button is depressed)? Or just perform the same functionality? Typically (in my experience anyway) it is best to avoid calling event handlers when unnessecary. It may be benifitial to have the event handler call a method, and also have the speech recognition call that method as well. Also, I dont think you need to use Invoke - everything seems to be running on the UI thread anyway.

This question has already been answered. Start a new discussion instead.