Пример #1
0
 private void HandleKeys(object sender, ArduinoButtonEventArgs e)
 {
     if (e.Left)
     {
         keybd_event((byte)VK_LEFT, 0, KEYEVENTF_EXTENDEDKEY | 0, 0);
     }
     else if (LastLeft)
     {
         keybd_event((byte)VK_LEFT, 0, KEYEVENTF_KEYUP | 0, 0);
     }
     if (e.Right)
     {
         keybd_event((byte)VK_RIGHT, 0, KEYEVENTF_EXTENDEDKEY | 0, 0);
     }
     else if (LastRight)
     {
         keybd_event((byte)VK_RIGHT, 0, KEYEVENTF_KEYUP | 0, 0);
     }
     if (e.Fire)
     {
         keybd_event((byte)VK_FIRE, 0, KEYEVENTF_EXTENDEDKEY | 0, 0);
     }
     else if (LastFire)
     {
         keybd_event((byte)VK_FIRE, 0, KEYEVENTF_KEYUP | 0, 0);
     }
 }
Пример #2
0
        private void ButtonThread()
        {
            while (true)
            {
                if (SerialPortManager.SerialPort.IsOpen)
                {
                    if (SerialPortManager.SerialPort.BytesToRead > 0)
                    {
                        if (Convert.ToChar(SerialPortManager.SerialPort.ReadByte()) == 'b')
                        {
                            int input = SerialPortManager.SerialPort.ReadByte();
                            ArduinoButtonEventArgs e;
                            switch (input)
                            {
                            case 7:
                                e = new ArduinoButtonEventArgs(true, true, true);
                                break;

                            case 6:
                                e = new ArduinoButtonEventArgs(true, true, false);
                                break;

                            case 5:
                                e = new ArduinoButtonEventArgs(true, false, true);
                                break;

                            case 4:
                                e = new ArduinoButtonEventArgs(true, false, false);
                                break;

                            case 3:
                                e = new ArduinoButtonEventArgs(false, true, true);
                                break;

                            case 2:
                                e = new ArduinoButtonEventArgs(false, true, false);
                                break;

                            case 1:
                                e = new ArduinoButtonEventArgs(false, false, true);
                                break;

                            case 0:
                                e = new ArduinoButtonEventArgs(false, false, false);
                                break;

                            default:
                                continue;
                            }

                            ButtonPressEvent.Invoke(this, e);
                        }
                    }
                }
            }
        }