Beispiel #1
0
 public static int String(this ITestableNetworkStream netStream, string str)
 {
     MultiPressCommand[] mpc = MultiPress.CreateMultiPressCommands(str);
     foreach (MultiPressCommand m in mpc)
     {
         for (int i = 0; i < m.Times; i++)
         {
             netStream.Command(Convert.ToChar(48 + m.Digit));
             Thread.Sleep(MultiPressDelayForSameKey);
         }
         Thread.Sleep(MultiPressDelayForNextKey);
     }
     return(0);
 }
        public async static Task <int> CommandStringAsync(this NetworkStream netStream, string str)
        {
            MultiPressCommand[] mpc = MultiPress.CreateMultiPressCommands(str);
            if (Properties.Settings.Default.LogCommands)
            {
                Program.FormShow.Log(Form1.ParsedElementsWriter, Form1.StdOut, new XElement("CommandStringAsync", str));
            }
            foreach (MultiPressCommand m in mpc)
            {
                for (int i = 0; i < m.Times; i++)
                {
                    await netStream.CommandAsync(Convert.ToChar(48 + m.Digit));

                    Thread.Sleep(Noxon.MultiPressDelayForSameKey);
                }
                Thread.Sleep(Noxon.MultiPressDelayForNextKey);
            }
            return(0);
        }
        private async void PictureBox1_MouseClick(object sender, MouseEventArgs e)
        {
            if (dragging)
            {
                return;
            }
            if (e.Button == MouseButtons.Right)
            {
                ((Form)this.TopLevelControl).Close();                                  // close remote if clicked right
            }
            double elapsed = stopwatch.Elapsed.TotalMilliseconds;

            if (stopwatch.IsRunning)
            {
                if (elapsed > Noxon.MultiPressDelayForNextKey)
                {
                    System.Diagnostics.Debug.WriteLine("PictureBox1_MouseClick(): restart stopwatch, elapsed ms = {0} > {1}", elapsed, Noxon.MultiPressDelayForNextKey);
                    stopwatch.Restart();
                    numberOfClicks = 0;
                }
            }
            else
            {
                stopwatch.Start();
                numberOfClicks = 0;
                System.Diagnostics.Debug.WriteLine("PictureBox1_MouseClick(): Start stopwatch");
            }
            Color color = zoneMap.GetPixel(e.X, e.Y);

            if (RemoteKeys.ContainsKey(color))
            {
                char command = RemoteKeys[color];
                // System.Diagnostics.Debug.WriteLine("Remote: key {0} detected for color {1}", command, color);
                if (command != ' ')
                {
                    if (Noxon.textEntry)
                    {
                        if ('0' <= command && command <= '9')
                        {
                            System.Diagnostics.Debug.WriteLine("Remote: digit {0} detected, elapsed = {1}, numberOfClicks = {2}", command, elapsed, numberOfClicks);
                            if (elapsed < 3 * Noxon.MultiPressDelayForSameKey)
                            {
                                numberOfClicks += e.Clicks;
                                if (Program.form.textBoxSearch.Text.Length < Program.form.textBoxSearch.MaxLength)
                                {
                                    string current = Program.form.textBoxSearch.TextLength > 0 ? Program.form.textBoxSearch.Text.Substring(0, (Program.form.textBoxSearch.TextLength - 1)) : "";
                                    Program.form.textBoxSearch.Text = current + MultiPress.Encoding(command, numberOfClicks);
                                    System.Diagnostics.Debug.WriteLine("PictureBox1_MouseClick(): replaced last search box char by '{0}' (numberOfClicks={1}, elapsed ms = {2} < {3})", MultiPress.Encoding(command, numberOfClicks), numberOfClicks, elapsed, Noxon.MultiPressDelayForSameKey);
                                }
                                stopwatch.Restart();
                            }
                            else
                            {
                                if (Program.form.textBoxSearch.Text.Length < Program.form.textBoxSearch.MaxLength)
                                {
                                    if (Program.form.textBoxSearch.Text.Length < Program.form.textBoxSearch.MaxLength)
                                    {
                                        Program.form.textBoxSearch.Text += MultiPress.Encoding(command, 1);
                                    }
                                    System.Diagnostics.Debug.WriteLine("PictureBox1_MouseClick(): added '{0}' to search box", MultiPress.Encoding(command, 1));
                                }
                                stopwatch.Restart();
                            }
                        }
                        else if (command == '<')
                        {
                            if (Program.form.textBoxSearch.TextLength > 0)
                            {
                                Program.form.textBoxSearch.Text = Program.form.textBoxSearch.Text.Substring(0, (Program.form.textBoxSearch.TextLength - 1));
                            }
                            stopwatch.Stop();
                        }
                        else if (command == 'R' && Program.form.textBoxSearch.Text.Length > 0)
                        {
                            Program.form.TextBoxSearch_KeyDown(this, new KeyEventArgs(Keys.Enter));
                            stopwatch.Stop();
                        }
                        else
                        {
                            await Noxon.netStream.GetNetworkStream().CommandAsync(command);
                        }
                    }
                    else
                    {
                        await Noxon.netStream.GetNetworkStream().CommandAsync(command);
                    }
                }
            }
        }