コード例 #1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BrailleIO_KeyPressed_EventArgs" /> class.
 /// </summary>
 /// <param name="keyCode">The key code.</param>
 public BrailleIO_KeyEventArgs(BrailleIO_DeviceButtonStates keyCode)
 {
     this.keyCode           = keyCode;
     this.keyboardCode      = BrailleIO_BrailleKeyboardButtonStates.None;
     this.additionalKeyCode = null;
     this.raw = null;
 }
コード例 #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BrailleIO_KeyPressed_EventArgs" /> class.
 /// </summary>
 /// <param name="keyCode">The key code.</param>
 /// <param name="raw">The original raw event data from the device.</param>
 /// <param name="keyboardCode">optional combined Braille keyboard button states.</param>
 /// <param name="additionalKeyCode">list of optional combined additional button states.</param>
 public BrailleIO_KeyEventArgs(BrailleIO_DeviceButtonStates keyCode, ref OrderedDictionary raw,
                               BrailleIO_BrailleKeyboardButtonStates keyboardCode   = BrailleIO_BrailleKeyboardButtonStates.None,
                               BrailleIO_AdditionalButtonStates[] additionalKeyCode = null)
 {
     this.keyCode           = keyCode;
     this.keyboardCode      = keyboardCode;
     this.additionalKeyCode = additionalKeyCode;
     this.raw = raw;
 }
コード例 #3
0
ファイル: Utils.cs プロジェクト: gasparramoa/BrailleIO
        /// <summary>
        /// Gets all released Braille keyboard buttons.
        /// </summary>
        /// <param name="state">The state.</param>
        /// <returns>Flag of all released Braille keyboard buttons</returns>
        public static BrailleIO_BrailleKeyboardButton GetAllUpBrailleKeyboardButtons(BrailleIO_BrailleKeyboardButtonStates state)
        {
            BrailleIO_BrailleKeyboardButton result = BrailleIO_BrailleKeyboardButton.None;

            try
            {
                result = (BrailleIO_BrailleKeyboardButton)GetButtonUpFlags((int)state);
            }
            catch (Exception) { }
            return(result);
        }
コード例 #4
0
ファイル: Utils.cs プロジェクト: gasparramoa/BrailleIO
        /// <summary>
        /// Gets the device button for one Braille keyboard button state.
        /// </summary>
        /// <param name="state">The state.</param>
        /// <returns>the button related to this state</returns>
        public static BrailleIO_BrailleKeyboardButton GetDeviceButtonFlagsOfState(BrailleIO_BrailleKeyboardButtonStates state)
        {
            BrailleIO_BrailleKeyboardButton buttons = BrailleIO_BrailleKeyboardButton.None;

            try
            {
                buttons = (BrailleIO_BrailleKeyboardButton)ShiftDownButtonsToUpButtonStates((int)state);
            }
            catch (Exception) { }
            return(buttons);
        }
コード例 #5
0
ファイル: Utils.cs プロジェクト: gasparramoa/BrailleIO
        /// <summary>
        /// Gets the 'down' state value for a certain Braille keyboard button.
        /// </summary>
        /// <param name="button">The button.</param>
        /// <returns>the enum value for the 'down' state of the button</returns>
        public static BrailleIO_BrailleKeyboardButtonStates GetDownStateForDeviceButton(BrailleIO_BrailleKeyboardButton button)
        {
            int val = (int)button;
            BrailleIO_BrailleKeyboardButtonStates result = BrailleIO_BrailleKeyboardButtonStates.None;

            try
            {
                result = (BrailleIO_BrailleKeyboardButtonStates)ShiftUpButtonsToUpDownStates(GetButtonUpFlags(val));
            }
            catch (Exception) { }
            return(result);
        }
コード例 #6
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);
        }
コード例 #7
0
        internal void firekeyStateChangedEvent(BrailleIO_DeviceButtonStates states,
                                               BrailleIO_BrailleKeyboardButtonStates keyboardCode,
                                               BrailleIO_AdditionalButtonStates[] additionalKeyCode,
                                               List <string> pressedKeys,
                                               List <string> releasedKeys,
                                               int timeStampTickCount)
        {
            OrderedDictionary raw = new OrderedDictionary();

            raw.Add("pressedKeys", pressedKeys);
            raw.Add("releasedKeys", releasedKeys);
            raw.Add("timeStampTickCount", timeStampTickCount);
            fireKeyStateChanged(states, ref raw, keyboardCode, additionalKeyCode);
            //fireKeyStateChanged(states, ref raw);
        }
コード例 #8
0
        /// <summary>Updates the list of pressed keyboard buttons.</summary>
        /// <param name="keyboardCode">The keyboard code.</param>
        /// <param name="pressedKbB">The pressed keyboard buttons.</param>
        /// <param name="releasedKbB">The released keyboard buttons.</param>
        protected virtual void updatePressedKeyboardButtons(
            BrailleIO_BrailleKeyboardButtonStates keyboardCode,
            out BrailleIO_BrailleKeyboardButton pressedKbB,
            out BrailleIO_BrailleKeyboardButton releasedKbB)
        {
            pressedKbB  = BrailleIO_BrailleKeyboardButton.None;
            releasedKbB = BrailleIO_BrailleKeyboardButton.None;

            if (keyboardCode != BrailleIO_BrailleKeyboardButtonStates.None)
            {
                lock (_syncLock)
                {
                    pressedKbB = Utils.GetAllDownBrailleKeyboardButtons(keyboardCode);
                    PressedBrailleKeyboardButtons = PressedBrailleKeyboardButtons | pressedKbB;
                    releasedKbB = Utils.GetAllUpBrailleKeyboardButtons(keyboardCode);
                    PressedBrailleKeyboardButtons = PressedBrailleKeyboardButtons & ~releasedKbB;
                }
            }
        }
コード例 #9
0
 /// <summary>Fires the key pressed event.</summary>
 /// <param name="keyCode">The key code.</param>
 /// <param name="raw">The raw hardware data.</param>
 /// <param name="keyboardButtonStates">The current pressed keyboard button states.</param>
 /// <param name="additionalButtonStates">The current pressed additional button states.</param>
 protected virtual void fireKeyPressed(
     BrailleIO_DeviceButtonStates keyCode,
     ref OrderedDictionary raw,
     BrailleIO_BrailleKeyboardButtonStates keyboardButtonStates,
     BrailleIO_AdditionalButtonStates[] additionalButtonStates
     )
 {
     if (keyPressed != null)
     {
         try
         {
             keyPressed.Invoke(
                 this,
                 new BrailleIO_KeyPressed_EventArgs(
                     keyCode, ref raw,
                     keyboardButtonStates, additionalButtonStates));
         }
         catch { }
     }
 }
コード例 #10
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BrailleIO_KeyStateChanged_EventArgs"/> class.
 /// </summary>
 /// <param name="keyCode">The key code.</param>
 /// <param name="raw">The original raw event data from the device.</param>
 public BrailleIO_KeyStateChanged_EventArgs(BrailleIO_DeviceButtonStates keyCode, ref OrderedDictionary raw,
                                            BrailleIO_BrailleKeyboardButtonStates keyboardCode   = BrailleIO_BrailleKeyboardButtonStates.None,
                                            BrailleIO_AdditionalButtonStates[] additionalKeyCode = null)
     : base(keyCode, ref raw, keyboardCode, additionalKeyCode)
 {
 }
コード例 #11
0
ファイル: Utils.cs プロジェクト: gasparramoa/BrailleIO
        /// <summary>
        /// Gets all pressed Braille keyboard buttons.
        /// </summary>
        /// <param name="state">The state.</param>
        /// <returns>Flag of all pressed Braille keyboard buttons</returns>
        public static BrailleIO_BrailleKeyboardButton GetAllDownBrailleKeyboardButtons(BrailleIO_BrailleKeyboardButtonStates state)
        {
            BrailleIO_BrailleKeyboardButton result = BrailleIO_BrailleKeyboardButton.None;

            try
            {
                result = (BrailleIO_BrailleKeyboardButton)ShiftDownButtonsToUpButtonStates(GetButtonDownFlags((int)state));
            }
            catch (Exception) { }
            return(result);
        }
コード例 #12
0
ファイル: ShowOff_Buttons.cs プロジェクト: mbranig/BrailleIO
        internal void fireKeyStateChangeEvent(BrailleIO_DeviceButtonStates states,
                                              BrailleIO_BrailleKeyboardButtonStates keyboardCode,
                                              BrailleIO_AdditionalButtonStates[] additionalKeyCode,
                                              List <string> pressedKeys,
                                              List <string> releasedKeys,
                                              int timeStampTickCount)
        {
            if (Ctr)
            {
                //check if pressed or released
                if (releasedKeys == null || releasedKeys.Count < 1) //pressed keys
                {
                    if (pressedKeys != null && pressedKeys.Count > 0)
                    {
                        foreach (string pk in pressedKeys)
                        {
                            if (_pressedButtons.Contains(pk))
                            {
                                UnmarkButtons(new List <String> {
                                    pk
                                });
                                _pressedButtons.Remove(pk);
                                _pressedStates.Remove(states);
                                _pressedKeyboradStates.Remove(keyboardCode);
                                if (additionalKeyCode != null && additionalKeyCode.Length > 0)
                                {
                                    _pressedFncStates.Remove(additionalKeyCode[0]);
                                }
                            }
                            else
                            {
                                _pressedButtons.Add(pk);
                                _pressedStates.Add(states);
                                _pressedKeyboradStates.Add(keyboardCode);
                                if (additionalKeyCode != null && additionalKeyCode.Length > 0)
                                {
                                    _pressedFncStates.Add(additionalKeyCode[0]);
                                }
                            }
                        }
                    }
                }
                else // released keys
                {
                    if (releasedKeys != null && releasedKeys.Count > 0)
                    {
                        foreach (string rk in releasedKeys)
                        {
                            if (_releasedButtons.Contains(rk))
                            {
                                UnmarkButtons(new List <String> {
                                    rk
                                });
                                _releasedButtons.Remove(rk);
                                _releasedStates.Remove(states);
                                _releasedKeybordStates.Remove(keyboardCode);
                                if (additionalKeyCode != null && additionalKeyCode.Length > 0)
                                {
                                    _releasedFncStates.Remove(additionalKeyCode[0]);
                                }
                            }
                            else
                            {
                                _releasedButtons.Add(rk);
                                _releasedStates.Add(states);
                                _releasedKeybordStates.Add(keyboardCode);
                                if (additionalKeyCode != null && additionalKeyCode.Length > 0)
                                {
                                    _releasedFncStates.Add(additionalKeyCode[0]);
                                }
                            }
                        }
                    }
                }

                MarkButtonAsPressed(_pressedButtons);
            }

            BrailleIO_DeviceButtonStates ps = BrailleIO_DeviceButtonStates.None;

            foreach (BrailleIO_DeviceButtonStates s in _pressedStates)
            {
                ps = ps | s;
            }
            BrailleIO_BrailleKeyboardButtonStates ks = BrailleIO_BrailleKeyboardButtonStates.None;

            foreach (BrailleIO_BrailleKeyboardButtonStates item in _pressedKeyboradStates)
            {
                ks |= item;
            }
            BrailleIO_AdditionalButtonStates ads = BrailleIO_AdditionalButtonStates.None;

            foreach (BrailleIO_AdditionalButtonStates item in _pressedFncStates)
            {
                ads |= item;
            }

            // fire always button pressed but wait for release
            if (ShowOffAdapter != null && pressedKeys != null && pressedKeys.Count > 0)
            {
                ShowOffAdapter.firekeyStateChangedEvent(ps, ks, new BrailleIO_AdditionalButtonStates[1] {
                    ads
                }, _pressedButtons, new List <String>(), timeStampTickCount);
            }
            //              ShowOffAdapter.firekeyStateChangedEvent(ps, _pressedButtons, new List<String>(), timeStampTickCount);


            if (Ctr)
            {
                return;      // break the release or reset functions
            }
            if (states == BrailleIO_DeviceButtonStates.None && pressedKeys == null && releasedKeys == null && timeStampTickCount == 0)
            {
                //check if this is because the ctr is released
                if (ShowOffAdapter != null)
                {
                    BrailleIO_DeviceButtonStates rs = BrailleIO_DeviceButtonStates.None;
                    foreach (BrailleIO_DeviceButtonStates s in _releasedStates)
                    {
                        rs = rs | s;
                    }
                    BrailleIO_BrailleKeyboardButtonStates rks = BrailleIO_BrailleKeyboardButtonStates.None;
                    foreach (BrailleIO_BrailleKeyboardButtonStates item in _releasedKeybordStates)
                    {
                        rks |= item;
                    }
                    // TODO: do for additional buttons
                    BrailleIO_AdditionalButtonStates rads = BrailleIO_AdditionalButtonStates.None;
                    foreach (BrailleIO_AdditionalButtonStates item in _releasedFncStates)
                    {
                        rads |= item;
                    }

                    ShowOffAdapter.firekeyStateChangedEvent(rs, rks, new BrailleIO_AdditionalButtonStates[1] {
                        rads
                    }, new List <String>(), _releasedButtons, timeStampTickCount);
                    //ShowOffAdapter.firekeyStateChangedEvent(rs, new List<String>(), _releasedButtons, timeStampTickCount);


                    UnmarkButtons(_releasedButtons);

                    _pressedButtons.Clear();
                    _releasedButtons.Clear();
                    _pressedStates.Clear();
                    _pressedKeyboradStates.Clear();
                    _pressedFncStates.Clear();
                    _releasedStates.Clear();
                    _releasedKeybordStates.Clear();
                    _releasedFncStates.Clear();
                }
            }
            else
            {
                if (ShowOffAdapter != null)
                {
                    ShowOffAdapter.firekeyStateChangedEvent(states, keyboardCode, additionalKeyCode, pressedKeys, releasedKeys, timeStampTickCount);
                    //ShowOffAdapter.firekeyStateChangedEvent(states, pressedKeys, releasedKeys, timeStampTickCount);
                }
            }
        }