Example #1
0
        private static void HandleInput()
        {
            while (commandsToExecute.Count > 0)
            {
                switch (commandsToExecute.Peek().code)
                {
                case Command.ActionCode.MOVE:
                    Command.Move move = (Command.Move)commandsToExecute.Dequeue();
                    MouseController.Move(move.dx * Properties.Settings.Default.Move / 5, move.dy * Properties.Settings.Default.Move / 5);
                    break;

                case Command.ActionCode.LEFTBUTTON:
                    Command.LeftButton left = (Command.LeftButton)commandsToExecute.Dequeue();
                    MouseController.Left(left.state);
                    break;

                case Command.ActionCode.RIGHTBUTTON:
                    Command.RightButton right = (Command.RightButton)commandsToExecute.Dequeue();
                    MouseController.Right(right.state);
                    break;

                case Command.ActionCode.SCROLL:
                    Command.Scroll scroll = (Command.Scroll)commandsToExecute.Dequeue();
                    System.Diagnostics.Debug.WriteLine(Properties.Settings.Default.Scroll);
                    MouseController.Scroll(scroll.scroll * Properties.Settings.Default.Scroll / 5);
                    break;

                case Command.ActionCode.ZOOM:
                    Command.Zoom zoom = (Command.Zoom)commandsToExecute.Dequeue();
                    MouseController.Zoom(zoom.zoom * Properties.Settings.Default.Zoom / 2);
                    break;
                }
            }
        }
Example #2
0
        private static void ProcessAndValidate(byte[] input)
        {
            if (commandsToExecute == null)
            {
                commandsToExecute = new Queue <Command>();
                commandsToSend    = new Queue <Command>();
            }
            byte[] batch = (byte[])input;
            int    i     = 0;

            while (i < batch.Length)
            {
                byte action = batch[i];
                if (!Command.ActionCode.IsDefined(typeof(Command.ActionCode), action))
                {
                    i = batch.Length;
                }
                else
                {
                    Command c;
                    switch ((Command.ActionCode)action)
                    {
                    case Command.ActionCode.MOVE:
                        if (batch.Length - i >= 3)       // 2 bytes: dx,dy + 1 type byte, 3 IN TOTAL
                        {
                            c = new Command.Move((sbyte)batch[i + 1], (sbyte)batch[i + 2]);
                            EnqueueCommand(c);
                            i += 3;
                        }
                        else
                        {
                            i = batch.Length;
                        }
                        break;

                    case Command.ActionCode.LEFTBUTTON:
                        if (batch.Length - i >= 2)       // 1 byte: status + 1 type byte, 2 IN TOTAL
                        {
                            c = new Command.LeftButton(batch[i + 1]);
                            EnqueueCommand(c);
                            i += 2;
                        }
                        else
                        {
                            i = batch.Length;
                        }
                        break;

                    case Command.ActionCode.RIGHTBUTTON:
                        if (batch.Length - i >= 2)       // 1 byte: status + 1 type byte, 2 IN TOTAL
                        {
                            c = new Command.RightButton(batch[i + 1]);
                            EnqueueCommand(c);
                            i += 2;
                        }
                        else
                        {
                            i = batch.Length;
                        }
                        break;

                    case Command.ActionCode.SCROLL:
                        if (batch.Length - i >= 2)        // 1 byte: data + 1 type byte, 2 IN TOTAL
                        {
                            c = new Command.Scroll((sbyte)batch[i + 1]);
                            EnqueueCommand(c);
                            i += 2;
                        }
                        else
                        {
                            i = batch.Length;
                        }
                        break;

                    case Command.ActionCode.ZOOM:
                        if (batch.Length - i >= 2)        // 1 byte: data + 1 type byte, 2 IN TOTAL
                        {
                            c = new Command.Zoom((sbyte)batch[i + 1]);
                            EnqueueCommand(c);
                            i += 2;
                        }
                        else
                        {
                            i = batch.Length;
                        }
                        break;
                    }
                }
            }
            NotifyThread();
        }