Example #1
0
        private void _HostKeyboard_KeyUp(USBH_Keyboard sender, USBH_KeyboardEventArgs args)
        {
            // Handle the key press ASAP.
            var key = (KeyboardKey)args.Key;

            _OutBuffer.KeyUp(key);
            var shiftPressed   = (_Keyboard.GetKeyState(USBH_Key.LeftShift) == USBH_KeyState.Down) || (_Keyboard.GetKeyState(USBH_Key.RightShift) == USBH_KeyState.Down);
            var controlPressed = (_Keyboard.GetKeyState(USBH_Key.LeftCtrl) == USBH_KeyState.Down) || (_Keyboard.GetKeyState(USBH_Key.RightCtrl) == USBH_KeyState.Down);
            var altPressed     = (_Keyboard.GetKeyState(USBH_Key.LeftAlt) == USBH_KeyState.Down) || (_Keyboard.GetKeyState(USBH_Key.RightAlt) == USBH_KeyState.Down);
            var logoPressed    = (_Keyboard.GetKeyState(USBH_Key.LeftGUI) == USBH_KeyState.Down) || (_Keyboard.GetKeyState(USBH_Key.RightGUI) == USBH_KeyState.Down);

            // Handle inactivity and minimum time before start state.
            _MinimumKeystrokes--;

            if (_SelectedFiddle == null && _PublishedFiddle == null && _MinimumDelay < Utility.GetMachineTime() && _MinimumKeystrokes <= 0)
            {
                // Transition to active state by selecting the next fiddle to publish.
                SelectNextFiddle();
            }

            if (_PublishedFiddle != null)
            {
                // Call fiddler to adjust our output.
                _PublishedFiddle.Implementation.ApplyOnKeyUp(_OutBuffer, key, shiftPressed, controlPressed, altPressed, logoPressed);
                if (_PublishedFiddle.Implementation.IsComplete)
                {
                    // Fiddle was applied, schedule the next one.
                    _PublishedFiddle.Implementation.AfterCompletion();
                    _PublishedFiddle = null;
                    _Ui.FiddlesMade  = _Ui.FiddlesMade + 1;
                    SelectNextFiddle();
                }
            }
        }
Example #2
0
        private void _HostKeyboard_KeyDown(USBH_Keyboard sender, USBH_KeyboardEventArgs args)
        {
            // Handle the key event ASAP.
            var key = (KeyboardKey)args.Key;

            _OutBuffer.KeyDown(key);
            var shiftPressed   = (_Keyboard.GetKeyState(USBH_Key.LeftShift) == USBH_KeyState.Down) || (_Keyboard.GetKeyState(USBH_Key.RightShift) == USBH_KeyState.Down);
            var controlPressed = (_Keyboard.GetKeyState(USBH_Key.LeftCtrl) == USBH_KeyState.Down) || (_Keyboard.GetKeyState(USBH_Key.RightCtrl) == USBH_KeyState.Down);
            var altPressed     = (_Keyboard.GetKeyState(USBH_Key.LeftAlt) == USBH_KeyState.Down) || (_Keyboard.GetKeyState(USBH_Key.RightAlt) == USBH_KeyState.Down);
            var logoPressed    = (_Keyboard.GetKeyState(USBH_Key.LeftGUI) == USBH_KeyState.Down) || (_Keyboard.GetKeyState(USBH_Key.RightGUI) == USBH_KeyState.Down);

            // Handle inactivity and minimum time before start state.
            this.SetInactivityTimeout();

            if (_IsInactive)
            {
                // Transition to initial delay state by initialising the minimum variables.
                SetMinimumCounters();
                _IsInactive = false;
            }

            if (_PublishedFiddle != null)
            {
                // Call fiddler to adjust our output.
                _PublishedFiddle.Implementation.ApplyOnKeyDown(_OutBuffer, key, shiftPressed, altPressed, controlPressed, logoPressed);
                if (_PublishedFiddle.Implementation.IsComplete)
                {
                    // Fiddle was applied, schedule the next one.
                    _PublishedFiddle.Implementation.AfterCompletion();
                    _PublishedFiddle = null;
                    _Ui.FiddlesMade  = _Ui.FiddlesMade + 1;
                    SelectNextFiddle();
                }
            }
        }
Example #3
0
 static void _keyboard_KeyUp(USBH_Keyboard sender, USBH_KeyboardEventArgs args)
 {
     if (args.KeyAscii == 0)
     {
         Core.RaiseKeyboardAltKeyEvent((int)args.Key, false);
     }
     else
     {
         Core.RaiseKeyboardKeyEvent(args.KeyAscii, false);
     }
 }
Example #4
0
 /// <summary>
 /// Raises the <see cref="KeyboardDisconnected"/> event.
 /// </summary>
 /// <param name="sender">The <see cref="USBHost"/> object that raised the event.</param>
 /// <param name="Keyboard">The <see cref="USBH_Keyboard"/> object associated with the event.</param>
 protected virtual void OnKeyboardDisconnectedEvent(USBHost sender, USBH_Keyboard Keyboard)
 {
     if (_OnKeyboardDisconnected == null)
     {
         _OnKeyboardDisconnected = new KeyboardDisconnectedEventHandler(OnKeyboardDisconnectedEvent);
     }
     if (Program.CheckAndInvoke(KeyboardDisconnected, _OnKeyboardDisconnected, sender, Keyboard))
     {
         KeyboardDisconnected(sender, Keyboard);
     }
 }
Example #5
0
        private void USBHostController_DeviceConnectedEvent(USBH_Device device)
        {
            try
            {
                switch (device.TYPE)
                {
                case USBH_DeviceType.MassStorage:
                    lock (this.storageDevices)
                    {
                        var ps = new PersistentStorage(device);
                        ps.MountFileSystem();
                        this.storageDevices.Add(device.ID, ps);
                    }

                    break;

                case USBH_DeviceType.Mouse:
                    lock (this.mice)
                    {
                        var mouse = new USBH_Mouse(device);
                        mouse.SetCursorBounds(int.MinValue, int.MaxValue, int.MinValue, int.MaxValue);
                        this.mice.Add(device.ID, mouse);
                        this.OnMouseConnectedEvent(this, mouse);
                    }

                    break;

                case USBH_DeviceType.Keyboard:
                    lock (this.keyboards)
                    {
                        var keyboard = new USBH_Keyboard(device);
                        this.keyboards.Add(device.ID, keyboard);
                        this.OnKeyboardConnectedEvent(this, keyboard);
                    }

                    break;

                case USBH_DeviceType.Webcamera:
                    ErrorPrint("Use GTM.GHIElectronics.Camera for USB WebCamera support.");
                    break;

                default:
                    ErrorPrint("USB device is not supported by the Gadgeteer driver. More devices are supported by the GHI USB Host driver. Remove the USB Host from the designer, and proceed without using Gadgeteer code.");
                    break;
                }
            }
            catch (Exception)
            {
                ErrorPrint("Unable to identify USB Host device.");
            }
        }
Example #6
0
 static void DeviceDisconnectedEvent(USBH_Device device)
 {
     if (device.TYPE == USBH_DeviceType.Keyboard)
     {
         _keyboard.KeyDown -= _keyboard_KeyDown;
         _keyboard.KeyUp   -= _keyboard_KeyUp;
         _keyboard          = null;
     }
     else if (device.TYPE == USBH_DeviceType.Mouse)
     {
         _mouse.MouseMove   -= _mouse_MouseMove;
         _mouse              = null;
         Core.MouseAvailable = false;
     }
 }
Example #7
0
        private void _Keyboard_Disconnected(USBH_Keyboard sender, USBH_KeyboardEventArgs args)
        {
            // Unhook event handlers and null our host keyboard.
            _Keyboard.KeyUp        -= new USBH_KeyboardEventHandler(_HostKeyboard_KeyUp);
            _Keyboard.KeyDown      -= new USBH_KeyboardEventHandler(_HostKeyboard_KeyDown);
            _Keyboard.Disconnected -= new USBH_KeyboardEventHandler(_Keyboard_Disconnected);
            _Keyboard = null;

            // Null any events / state.
            _NextFiddleEvents.Change(Timeout.Infinite, Timeout.Infinite);
            _InactivityTimer.Change(Timeout.Infinite, Timeout.Infinite);
            _PublishedFiddle   = null;
            _SelectedFiddle    = null;
            _MinimumKeystrokes = Int32.MaxValue;
            _MinimumDelay      = TimeSpan.MaxValue;
            _IsInactive        = false;
            _Ui.CurrentState   = UnitState.None;
        }
Example #8
0
 static void DeviceConnectedEvent(USBH_Device device)
 {
     if (device.TYPE == USBH_DeviceType.Keyboard)
     {
         _keyboard          = new USBH_Keyboard(device);
         _keyboard.KeyDown += _keyboard_KeyDown;
         _keyboard.KeyUp   += _keyboard_KeyUp;
         Debug.Print("Keyboard attached");
     }
     else if (device.TYPE == USBH_DeviceType.Mouse)
     {
         _mouse = new USBH_Mouse(device);
         _mouse.SetCursorBounds(0, Core.ScreenWidth, 0, Core.ScreenHeight);
         _mouse.SetCursor(0, 0);
         _mouse.Scale(20);
         _mouse.MouseMove   += _mouse_MouseMove;
         _mouse.MouseDown   += _mouse_MouseDown;
         _mouse.MouseUp     += _mouse_MouseUp;
         Core.MouseAvailable = true;
         Debug.Print("Mouse attached");
     }
 }
Example #9
0
        public void BeginMonitorKeyboardFrom(USBH_Device device)
        {
            _Keyboard               = new USBH_Keyboard(device);
            _Keyboard.KeyUp        += new USBH_KeyboardEventHandler(_HostKeyboard_KeyUp);
            _Keyboard.KeyDown      += new USBH_KeyboardEventHandler(_HostKeyboard_KeyDown);
            _Keyboard.Disconnected += new USBH_KeyboardEventHandler(_Keyboard_Disconnected);

            // Create a random seed using:
            uint seed = _Config.RandomSeed;                                             // A random number from the internet!

            seed  = seed ^ (uint)(((uint)device.VENDOR_ID << 16) | device.PRODUCT_ID);  // The USB vendor and device ids.
            seed  = seed ^ (uint)(device.ID << 9);                                      // Some other USB ID.
            seed  = seed ^ (uint)(Utility.GetMachineTime().Ticks & 0x00000000ffffffff); // The current time.
            _Rand = new Random((int)seed);

            // Nothing is scheduled up front, we have to wait for the minimum time & keystrokes before anything happens.
            SetMinimumCounters();
            _NextFiddleEvents.Change(Timeout.Infinite, Timeout.Infinite);
            _InactivityTimer.Change(Timeout.Infinite, Timeout.Infinite);
            _PublishedFiddle = null;
            _SelectedFiddle  = null;
            _IsInactive      = false;
        }