コード例 #1
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);
                }
            }
        }
コード例 #2
0
        internal void fireKeyStateChangeEvent(BrailleIO_DeviceButtonStates states,
                                              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);
                            }
                            else
                            {
                                _pressedButtons.Add(pk);
                                _pressedStates.Add(states);
                            }
                        }
                    }
                }
                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);
                            }
                            else
                            {
                                _releasedButtons.Add(rk);
                                _releasedStates.Add(states);
                            }
                        }
                    }
                }

                MarkButtonAsPressed(_pressedButtons);
            }

            BrailleIO_DeviceButtonStates ps = BrailleIO_DeviceButtonStates.None;

            foreach (BrailleIO_DeviceButtonStates s in _pressedStates)
            {
                ps = ps | s;
            }

            // fire always button pressed but wait for release
            if (ShowOffAdapter != null && pressedKeys != null && pressedKeys.Count > 0)
            {
                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;
                    }

                    ShowOffAdapter.firekeyStateChangedEvent(rs, new List <String>(), _releasedButtons, timeStampTickCount);

                    UnmarkButtons(_releasedButtons);

                    _pressedButtons.Clear();
                    _releasedButtons.Clear();
                    _pressedStates.Clear();
                    _releasedStates.Clear();
                }
            }
            else
            {
                if (ShowOffAdapter != null)
                {
                    ShowOffAdapter.firekeyStateChangedEvent(states, pressedKeys, releasedKeys, timeStampTickCount);
                }
            }
        }