Beispiel #1
0
        private char GetCombinationChar(KeyCombination combination, KeyPressInfo firstCombinationKey, bool escaped)
        {
            if (escaped)
            {
                bool useUpper;
                if (combination.IsEscapedCharacterCapsLockSensitive)
                {
                    useUpper = firstCombinationKey.ShiftPressed && !firstCombinationKey.CapsLockPressed ||
                               !firstCombinationKey.ShiftPressed && firstCombinationKey.CapsLockPressed;
                }
                else
                {
                    useUpper = firstCombinationKey.ShiftPressed;
                }

                return(useUpper ? combination.EscapedCharacterUpperCase.Value : combination.EscapedCharacterLowerCase.Value);
            }
            else
            {
                bool useUpper;
                if (combination.IsCharacterCapsLockSensitive)
                {
                    useUpper = firstCombinationKey.ShiftPressed && !firstCombinationKey.CapsLockPressed ||
                               !firstCombinationKey.ShiftPressed && firstCombinationKey.CapsLockPressed;
                }
                else
                {
                    useUpper = firstCombinationKey.ShiftPressed;
                }

                return(useUpper ? combination.CharacterUpperCase : combination.CharacterLowerCase);
            }
        }
Beispiel #2
0
        private void ButtonAddClick(object sender, RoutedEventArgs e)
        {
            try
            {
                var keyPressWindow = new KeyPressWindow();
                keyPressWindow.ShowDialog();
                if (keyPressWindow.DialogResult.HasValue && keyPressWindow.DialogResult.Value)
                {
                    //Clicked OK
                    var keyPressInfo = new KeyPressInfo();
                    keyPressInfo.LengthOfBreak    = (KeyPressLength)keyPressWindow.ComboBoxBreak.SelectedItem;
                    keyPressInfo.VirtualKeyCodes  = KeyPress.SplitStringKeyCodes(keyPressWindow.TextBoxKeyPress.Text);
                    keyPressInfo.LengthOfKeyPress = (KeyPressLength)keyPressWindow.ComboBoxKeyPressTime.SelectedItem;
                    _sortedList.Add(GetNewKeyValue(), keyPressInfo);

                    DataGridSequences.DataContext = _sortedList;
                    DataGridSequences.ItemsSource = _sortedList;
                    DataGridSequences.Items.Refresh();
                    SetIsDirty();
                    SetFormState();
                }
            }
            catch (Exception ex)
            {
                Common.ShowErrorMessageBox(ex);
            }
        }
 public KeyPressWindow(KeyPressInfo keyPressInfo)
 {
     InitializeComponent();
     //comboBoxBreak.ItemsSource = Enum.GetValues(typeof(KeyPressLength));
     ComboBoxBreak.SelectedItem        = keyPressInfo.LengthOfBreak;
     TextBoxKeyPress.Text              = keyPressInfo.VirtualKeyCodesAsString;
     ComboBoxKeyPressTime.SelectedItem = keyPressInfo.LengthOfKeyPress;
     SetFormState();
     TextBoxKeyPress.Focus();
 }
Beispiel #4
0
 public KeyPressReadingBigWindow(KeyPressInfo keyPressInfo, bool supportIndefinite = true)
 {
     InitializeComponent();
     //comboBoxBreak.ItemsSource = Enum.GetValues(typeof(KeyPressLength));
     ComboBoxBreak.SelectedItem        = keyPressInfo.LengthOfBreak;
     TextBoxKeyPress.Text              = keyPressInfo.VirtualKeyCodesAsString;
     ComboBoxKeyPressTime.SelectedItem = keyPressInfo.LengthOfKeyPress;
     _supportIndefinite = supportIndefinite;
     SetFormState();
     TextBoxKeyPress.Focus();
 }
Beispiel #5
0
        public void KeypressInfo_MustBe_Clonable()
        {
            KeyPressInfo source = new();

            source.LengthOfKeyPress = KeyPressLength.SecondAndHalf;
            source.LengthOfBreak    = KeyPressLength.FortySecs;

            KeyPressInfo cloned = source.CloneJson();

            Assert.NotNull(cloned);
            Assert.Equal(KeyPressLength.SecondAndHalf, cloned.LengthOfKeyPress);
            Assert.Equal(KeyPressLength.FortySecs, cloned.LengthOfBreak);
        }
Beispiel #6
0
        private void AddKeyPress()
        {
            var keyPressWindow = new KeyPressReadingBigWindow(_supportIndefinite);

            keyPressWindow.ShowDialog();
            if (keyPressWindow.DialogResult.HasValue && keyPressWindow.DialogResult.Value)
            {
                // Clicked OK
                var keyPressInfo = new KeyPressInfo
                {
                    LengthOfBreak    = (KeyPressLength)keyPressWindow.ComboBoxBreak.SelectedItem,
                    VirtualKeyCodes  = KeyPress.SplitStringKeyCodes(keyPressWindow.TextBoxKeyPress.Text),
                    LengthOfKeyPress = (KeyPressLength)keyPressWindow.ComboBoxKeyPressTime.SelectedItem
                };
                _sortedList.Add(GetNewKeyValue(), keyPressInfo);

                DataGridSequences.DataContext = _sortedList;
                DataGridSequences.ItemsSource = _sortedList;
                DataGridSequences.Items.Refresh();
                SetIsDirty();
                SetFormState();
            }
        }
Beispiel #7
0
 private KeyCombination FindCombination(KeyPressInfo combinationPressInfo)
 {
     return(FindCombination(new List <KeyPressInfo> {
         combinationPressInfo
     }));
 }
Beispiel #8
0
        private void HandleKeyDown(RawKeyEventArgs args)
        {
            LastKeyDownOrRestart = DateTime.Now;
            // Container.Log(false, "{0} down", args.Key);

            if (Context.IsSendingKey)
            {
                return;
            }

            if (!IsActive)
            {
                return;
            }

            Context.NextUpKeyToIgnore = null;

            if (Settings.UseEscape && args.Key == Key.Escape)
            {
                List <char>         chars;
                List <KeyPressInfo> keysUsedForLastLetter;
                bool effectiveEscape = EscapeCombination(Context.LastCombinationKeys, out chars, out keysUsedForLastLetter);

                if (effectiveEscape)
                {
                    args.IsHandled = true;
                    SendBackSpace();
                    SendChars(chars);
                }

                Context.LastCombinationKeys = keysUsedForLastLetter;

                LogState();

                return;
            }

            var newKey = new KeyPressInfo
            {
                Key                  = args.Key,
                CapsLockPressed      = Control.IsKeyLocked(Keys.CapsLock),
                ShiftPressed         = User32.IsAsyncKeyPressed(Keys.LShiftKey, Keys.RShiftKey),
                AltPressed           = User32.IsAsyncKeyPressed(Keys.LMenu, Keys.RMenu),
                ControlPressed       = User32.IsAsyncKeyPressed(Keys.LControlKey, Keys.RControlKey),
                WndPressed           = User32.IsAsyncKeyPressed(Keys.LWin, Keys.RWin),
                FocusedWindowHandler = User32.GetForegroundWindow(),
                Escaped              = false
            };

            Context.LastCombinationKeys.Add(newKey);

            //if (newKey.Key != System.Windows.Input.Key.LeftCtrl && newKey.Key != System.Windows.Input.Key.LWin && newKey.Key != System.Windows.Input.Key.LeftAlt && newKey.Key != System.Windows.Input.Key.LeftShift)
            //{
            //    int i = 6;
            //}

            if (Context.LastCombinationKeys.Count > ActiveLayout.MaxCompinationLength)
            {
                Context.LastCombinationKeys.RemoveAt(0);
            }

            KeyCombination combination = FindNewKeyCombination();

            if (combination != null)
            {
                if (!IsTargetLayout)
                {
                    return;
                }

                args.IsHandled            = true;
                Context.NextUpKeyToIgnore = args.Key;
                if (combination.Keys.Count > 1)
                {
                    SendBackSpace();
                }

                SendChar(GetCombinationChar(combination, Context.LastCombinationKeys[0], false));

                Container.Log(false, "Sending {0}", combination.CharacterLowerCase);
            }

            LogState();
        }
Beispiel #9
0
 private void SetPressHold(Keys key, bool val)
 {
     if (this.ditKeyPressInfo.ContainsKey(key))
     {
         this.ditKeyPressInfo[key].PressHoldState = val;
     }
     else
     {
         KeyPressInfo info = new KeyPressInfo
         {
             PressHoldState = val
         };
         this.ditKeyPressInfo.Add(key, info);
     }
 }
Beispiel #10
0
 private int KeyboardHookProc(int nCode, int wParam, IntPtr lParam)
 {
     if ((nCode < 0) || (((this.OnKeyDownEvent == null) && (this.OnKeyUpEvent == null)) && (this.OnKeyPressEvent == null)))
     {
         goto Label_0219;
     }
     KeyboardHookStruct struct2 = (KeyboardHookStruct)Marshal.PtrToStructure(lParam, typeof(KeyboardHookStruct));
     Keys vkCode = (Keys)struct2.vkCode;
     if ((wParam != 0x100) && (wParam != 260))
     {
         goto Label_0143;
     }
     if (IsCtrlKeys(vkCode))
     {
         this.IsDownControl = true;
         vkCode = Keys.Control;
     }
     else if (IsAltKeys(vkCode))
     {
         this.IsDownAlt = true;
         vkCode = Keys.Alt;
     }
     else if (IsShiftKeys(vkCode))
     {
         this.IsDownShift = true;
         vkCode = Keys.Shift;
     }
     if (this.OnKeyDownEvent != null)
     {
         this.OnKeyDownEvent(this, this.getKeyEventArg(vkCode));
     }
     KeyPressInfo keyPressInfo = this.GetKeyPressInfo(vkCode, false);
     if (keyPressInfo == null)
     {
         keyPressInfo = new KeyPressInfo();
         this.ditKeyPressInfo.Add(vkCode, keyPressInfo);
     }
     else
     {
         if (this.OnKeyManyClick != null)
         {
             TimeSpan span = (TimeSpan)(DateTime.Now - keyPressInfo.LastPressTime);
             if (span.TotalMilliseconds <= this.ManyTimeout)
             {
                 if (keyPressInfo.PressHoldState)
                 {
                     keyPressInfo.KeyPressTimes++;
                     this.OnKeyManyClick(this, new KeyManyEventArgs(vkCode, keyPressInfo.KeyPressTimes));
                 }
                 goto Label_013C;
             }
         }
         keyPressInfo.KeyPressTimes = 1;
         keyPressInfo.LastPressTime = DateTime.Now;
     }
     Label_013C:
     keyPressInfo.PressHoldState = false;
     Label_0143:
     if ((wParam == 0x101) || (wParam == 0x105))
     {
         if (IsCtrlKeys(vkCode))
         {
             this.IsDownControl = false;
             vkCode = Keys.Control;
         }
         else if (IsAltKeys(vkCode))
         {
             this.IsDownAlt = false;
             vkCode = Keys.Alt;
         }
         else if (IsShiftKeys(vkCode))
         {
             this.IsDownShift = false;
             vkCode = Keys.Shift;
         }
         if (this.OnKeyUpEvent != null)
         {
             this.OnKeyUpEvent(this, this.getKeyEventArg(vkCode));
         }
         this.SetPressHold(vkCode, true);
     }
     if ((this.OnKeyPressEvent != null) && (wParam == 0x100))
     {
         byte[] pbKeyState = new byte[0x100];
         GetKeyboardState(pbKeyState);
         byte[] lpwTransKey = new byte[2];
         if (ToAscii(struct2.vkCode, struct2.scanCode, pbKeyState, lpwTransKey, struct2.flags) == 1)
         {
             KeyPressEventArgs e = new KeyPressEventArgs((char)lpwTransKey[0]);
             this.OnKeyPressEvent(this, e);
         }
     }
     Label_0219:
     return CallNextHookEx(hKeyboardHook, nCode, wParam, lParam);
 }
Beispiel #11
0
 private KeyPressInfo GetKeyPressInfo(Keys key, bool NullToDefault)
 {
     KeyPressInfo info = null;
     if (this.ditKeyPressInfo.ContainsKey(key))
     {
         return this.ditKeyPressInfo[key];
     }
     if (NullToDefault)
     {
         info = new KeyPressInfo();
         this.ditKeyPressInfo.Add(key, info);
     }
     return info;
 }