Beispiel #1
0
        /// <summary>
        /// Gets the 'down' state value for a certain device button.
        /// </summary>
        /// <param name="button">The button.</param>
        /// <returns>the enum value for the 'down' state of the button</returns>
        public static BrailleIO_DeviceButtonStates GetDownStateForDeviceButton(BrailleIO_DeviceButton button)
        {
            string name = button.ToString() + "Down";

            if (Enum.IsDefined(typeof(BrailleIO_DeviceButtonStates), name))
            {
                return((BrailleIO_DeviceButtonStates)Enum.Parse(typeof(BrailleIO_DeviceButtonStates), name));
            }
            return(BrailleIO_DeviceButtonStates.Unknown);
        }
Beispiel #2
0
        /// <summary>
        /// Gets all released device buttons.
        /// </summary>
        /// <param name="state">The state.</param>
        /// <returns>Flag of all released device buttons</returns>
        public static BrailleIO_DeviceButton GetAllUpDeviceButtons(BrailleIO_DeviceButtonStates state)
        {
            BrailleIO_DeviceButton result = BrailleIO_DeviceButton.None;

            try
            {
                result = (BrailleIO_DeviceButton)GetButtonUpFlags((int)state);
            }
            catch (Exception) { }
            return(result);
        }
Beispiel #3
0
        /// <summary>
        /// Gets the device button for one certain button state.
        /// </summary>
        /// <param name="state">The state.</param>
        /// <returns>the button related to this state</returns>
        public static BrailleIO_DeviceButton GetDeviceButtonFlagsOfState(BrailleIO_DeviceButtonStates state)
        {
            BrailleIO_DeviceButton buttons = BrailleIO_DeviceButton.None;

            try
            {
                buttons = (BrailleIO_DeviceButton)ShiftDownButtonsToUpButtonStates((int)state);
            }
            catch (Exception) { }
            return(buttons);
        }
Beispiel #4
0
        /// <summary>
        /// Gets all pressed device buttons.
        /// </summary>
        /// <param name="state">The state.</param>
        /// <returns>Flag of all pressed device buttons</returns>
        public static BrailleIO_DeviceButton GetAllDownDeviceButtons(BrailleIO_DeviceButtonStates state)
        {
            BrailleIO_DeviceButton result = BrailleIO_DeviceButton.None;

            try
            {
                result = (BrailleIO_DeviceButton)ShiftDownButtonsToUpButtonStates(GetButtonDownFlags((int)state));
            }
            catch (Exception) { }
            return(result);
        }
Beispiel #5
0
        /// <summary>
        /// Checks if a key combination was released.
        /// </summary>
        /// <param name="pressed">The pressed general buttons.</param>
        /// <param name="released">The released general buttons.</param>
        /// <param name="pressedKbB">The pressed Braille keyboard buttons.</param>
        /// <param name="releasedKbB">The released Braille keyboard buttons.</param>
        /// <param name="pressedAdBs">The pressed additional buttons.</param>
        /// <param name="releasedAdBs">The released additional buttons.</param>
        private void checkForKeyCombination(
            BrailleIO_DeviceButton pressed,
            BrailleIO_DeviceButton released,
            BrailleIO_BrailleKeyboardButton pressedKbB,
            BrailleIO_BrailleKeyboardButton releasedKbB,
            Dictionary <int, BrailleIO_AdditionalButton> pressedAdBs,
            Dictionary <int, BrailleIO_AdditionalButton> releasedAdBs)
        {
            //System.Diagnostics.Debug.WriteLine("---- pressed: " + pressed);
            //System.Diagnostics.Debug.WriteLine("---- released: " + released);
            //System.Diagnostics.Debug.WriteLine("---- pressedKbB: " + pressedKbB);
            //System.Diagnostics.Debug.WriteLine("---- releasedKbB: " + releasedKbB);
            //System.Diagnostics.Debug.WriteLine("---- pressedAdBs: " + String.Join(", ", pressedAdBs.Values));
            //System.Diagnostics.Debug.WriteLine("---- releasedAdBs: " + String.Join(", ", releasedAdBs.Values));

            if (keyCombinationTimer != null) // if timer is running for collecting released events
            {
                keyCombinationTimer.Stop();  // stop further expiring

                if (!(Kc is KeyCombinationItem))
                {
                    Kc = new KeyCombinationItem(
                        BrailleIO_DeviceButton.None,
                        BrailleIO_DeviceButton.None,
                        BrailleIO_BrailleKeyboardButton.None,
                        BrailleIO_BrailleKeyboardButton.None,
                        null, null);
                }

                KeyCombinationItem kc = (KeyCombinationItem)Kc;

                // general keys
                kc.PressedGeneralKeys   = (this.PressedDeviceButtons & ~BrailleIO_DeviceButton.Unknown);
                kc.ReleasedGeneralKeys |= released;
                kc.ReleasedGeneralKeys  = kc.ReleasedGeneralKeys & ~kc.PressedGeneralKeys & ~BrailleIO_DeviceButton.Unknown;

                // keyboard
                kc.PressedKeyboardKeys   = this.PressedBrailleKeyboardButtons;
                kc.ReleasedKeyboardKeys |= releasedKbB;
                kc.ReleasedKeyboardKeys  = kc.ReleasedKeyboardKeys & ~kc.PressedKeyboardKeys;

                // additional
                kc.PressedAdditionalKeys  = this.PressedAdditionalButtons;
                kc.ReleasedAdditionalKeys = Utils.CombineAdditionalButtonCollections(kc.ReleasedAdditionalKeys, pressedAdBs);

                Kc = kc; // store globally
                keyCombinationTimer.Start();

                if (!kc.AreButtonsPressed()) //if no more buttons pressed
                {
                    t_Elapsed(keyCombinationTimer, null);
                }
            }
        }
Beispiel #6
0
        /// <summary>
        /// Gets the 'down' state value for a certain device button.
        /// </summary>
        /// <param name="button">The button.</param>
        /// <returns>the enum value for the 'down' state of the button</returns>
        public static BrailleIO_DeviceButtonStates GetDownStateForDeviceButton(BrailleIO_DeviceButton button)
        {
            int val = (int)button;
            BrailleIO_DeviceButtonStates result = BrailleIO_DeviceButtonStates.None;

            try
            {
                result = (BrailleIO_DeviceButtonStates)ShiftUpButtonsToUpDownStates(GetButtonUpFlags(val));
            }
            catch (Exception) { }
            return(result);
        }
Beispiel #7
0
        /// <summary>
        /// Fires a key state changed event.
        /// </summary>
        /// <param name="keyCode">The key code.</param>
        /// <param name="raw">The raw.</param>
        /// <param name="keyboardCode">optional combined Braille keyboard button states.</param>
        /// <param name="additionalKeyCode">list of optional combined additional button states.</param>
        protected virtual void fireKeyStateChanged(
            BrailleIO_DeviceButtonStates keyCode,
            ref OrderedDictionary raw,
            BrailleIO_BrailleKeyboardButtonStates keyboardCode   = BrailleIO_BrailleKeyboardButtonStates.None,
            BrailleIO_AdditionalButtonStates[] additionalKeyCode = null)
        {
            BrailleIO_DeviceButton pressed  = BrailleIO_DeviceButton.None;
            BrailleIO_DeviceButton released = BrailleIO_DeviceButton.None;

            BrailleIO_BrailleKeyboardButton pressedKbB  = BrailleIO_BrailleKeyboardButton.None;
            BrailleIO_BrailleKeyboardButton releasedKbB = BrailleIO_BrailleKeyboardButton.None;

            Dictionary <int, BrailleIO_AdditionalButton> pressedAdBs  = null;
            Dictionary <int, BrailleIO_AdditionalButton> releasedAdBs = null;

            try
            {
                // general buttons
                updatePressedDeviceButtons(keyCode, out pressed, out released);

                // braille keyboard buttons
                updatePressedKeyboardButtons(keyboardCode, out pressedKbB, out releasedKbB);

                // additional buttons
                updatePressedAdditionalButtons(additionalKeyCode, out pressedAdBs, out releasedAdBs);
            }
            catch
            {
                System.Diagnostics.Debug.WriteLine("ERROR in updating the current button states");
            }
            finally
            {
                // TODO: what to do to get it valid again?!
            }

            if (keyStateChanged != null)
            {
                try
                {
                    keyStateChanged(this, new BrailleIO_KeyStateChanged_EventArgs(keyCode, ref raw, keyboardCode, additionalKeyCode));
                }
                catch { }
            }

            checkForKeyCombination(
                pressed, released,
                pressedKbB, releasedKbB,
                pressedAdBs, releasedAdBs);
        }
        /// <summary>Updates the list of pressed device buttons.</summary>
        /// <param name="keyCode">The key code.</param>
        /// <param name="pressedDB">The pressed device buttons.</param>
        /// <param name="releasedDB">The released device buttons.</param>
        protected virtual void updatePressedDeviceButtons(BrailleIO_DeviceButtonStates keyCode,
                                                          out BrailleIO_DeviceButton pressedDB,
                                                          out BrailleIO_DeviceButton releasedDB)
        {
            pressedDB  = BrailleIO_DeviceButton.None;
            releasedDB = BrailleIO_DeviceButton.None;

            if (keyCode != BrailleIO_DeviceButtonStates.None)
            {
                lock (_syncLock)
                {
                    pressedDB            = Utils.GetAllDownDeviceButtons(keyCode);
                    PressedDeviceButtons = PressedDeviceButtons | pressedDB;
                    releasedDB           = Utils.GetAllUpDeviceButtons(keyCode);
                    PressedDeviceButtons = PressedDeviceButtons & ~releasedDB;
                }
            }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="KeyCombinationItem" /> struct.
        /// </summary>
        /// <param name="pressedGeneralKeys">The pressed general keys.</param>
        /// <param name="releasedGeneralKeys">The released general keys.</param>
        /// <param name="pressedKeyboardKeys">The pressed keyboard keys.</param>
        /// <param name="releasedKeyboardKeys">The released keyboard keys.</param>
        /// <param name="pressedAdditionalKeys">The pressed additional keys.</param>
        /// <param name="releasedAdditionalKeys">The released additional keys.</param>
        public KeyCombinationItem(
            BrailleIO_DeviceButton pressedGeneralKeys,
            BrailleIO_DeviceButton releasedGeneralKeys,
            BrailleIO_BrailleKeyboardButton pressedKeyboardKeys,
            BrailleIO_BrailleKeyboardButton releasedKeyboardKeys,
            BrailleIO_AdditionalButton[] pressedAdditionalKeys,
            BrailleIO_AdditionalButton[] releasedAdditionalKeys
            )
        {
            PressedGeneralKeys  = pressedGeneralKeys;
            ReleasedGeneralKeys = releasedGeneralKeys;

            PressedKeyboardKeys  = pressedKeyboardKeys;
            ReleasedKeyboardKeys = releasedKeyboardKeys;

            PressedAdditionalKeys  = pressedAdditionalKeys;
            ReleasedAdditionalKeys = releasedAdditionalKeys;
        }
Beispiel #10
0
        /// <summary>
        /// Initializes a new instance of the <see cref="KeyCombinationItem" /> struct.
        /// </summary>
        /// <param name="pressedGeneralKeys">The pressed general keys.</param>
        /// <param name="releasedGeneralKeys">The released general keys.</param>
        /// <param name="pressedKeyboardKeys">The pressed keyboard keys.</param>
        /// <param name="releasedKeyboardKeys">The released keyboard keys.</param>
        /// <param name="pressedAdditionalKeys">The pressed additional keys.</param>
        /// <param name="releasedAdditionalKeys">The released additional keys.</param>
        public KeyCombinationItem(
            BrailleIO_DeviceButton pressedGeneralKeys,
            BrailleIO_DeviceButton releasedGeneralKeys,
            BrailleIO_BrailleKeyboardButton pressedKeyboardKeys,
            BrailleIO_BrailleKeyboardButton releasedKeyboardKeys,
            BrailleIO_AdditionalButton[] pressedAdditionalKeys,
            BrailleIO_AdditionalButton[] releasedAdditionalKeys
            )
        {
            _pressedGeneralKeys  = pressedGeneralKeys;
            _releasedGeneralKeys = releasedGeneralKeys;

            _pressedKeyboardKeys  = pressedKeyboardKeys;
            _releasedKeyboardKeys = releasedKeyboardKeys;

            _pressedAdditionalKeys  = pressedAdditionalKeys;
            _releasedAdditionalKeys = releasedAdditionalKeys;

            _pressedString = _releasedString = "-";
            _pressed       = _released = 0;
        }