Hi all,

I was wondering what is the right way to send keystroke to my webbrowser flash games? Basically I just need to compare the variable canale with nIstU.Value. If is larger, I will send "spacebar" to the flash game else I will send "right" to the flash game.

Below is my coding:
Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;



namespace EEG_project_1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            string[] g = File.ReadAllLines("port.txt"); //Reading the port number
            serialPort1.PortName = g[0];
            //Load Game
            webBrowser1.Navigate(Application.StartupPath + "\\soopasprinta.swf");
    
        }

        byte[] Buff = new byte[15];
        byte Bcont = 0;
        byte Stato = 0;
        int cont = 0;
        


        private void serialPort1_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
        {
            int Canale;

            if (serialPort1.IsOpen == false) return;

            //The byte is managed in the buff array
            while (serialPort1.BytesToRead > 0)
            {

                byte tmpB = (byte)serialPort1.ReadByte();

                //Reading

             
                    if (Bcont == 0)
                    {//Synchronization
                    //Waiting for the synchronization is 0 or 1
                     if (tmpB >= 0xa5 || tmpB >= 0x5a)
                       
                         Buff[Bcont++] = tmpB;

                    }
                    else
                    {
                    
                       Buff[Bcont++] = tmpB;
                       

                        if (tmpB >= 0xa5 || tmpB >= 0x5a)
                        {
                            Canale = (int)Buff[4] + (int)Buff[5];
                          // data management

                     
                         if (Canale <= nIstD.Value)
                        {//Monitor if the value comes down under the threshold
                                    cont = 0;
                                    SendKeys.Send(" ");
                        }
                            else
                            {//Wait for the values to go back
                                cont++;
                                if (Canale >= nIstU.Value)
                                {//If the value returned above the threshold
                                    //I send the key pressed
                            
                                    SendKeys.Send(" ");

                                }

                            }

                            
                        }
                        Bcont = 3;
                    }
                }
            }
Any suggestion will be appreciated.

Thank you,
Louise