Пример #1
0
 private void DG1_KeyDown(object sender, KeyEventArgs e)
 {
     System.Windows.Input.KeyboardDevice kd = e.KeyboardDevice;
     if ((kd.GetKeyStates(Key.LeftCtrl) & kd.GetKeyStates(Key.V)) > 0 || (kd.GetKeyStates(Key.LeftCtrl) & kd.GetKeyStates(Key.V)) > 0)
     {
         DataGirdViewCellPaste();
     }
 }
Пример #2
0
 private void Window_KeyDown(object sender, KeyEventArgs e)
 {
     System.Windows.Input.KeyboardDevice kd = e.KeyboardDevice;
     if ((kd.GetKeyStates(Key.LeftAlt) & System.Windows.Input.KeyStates.Down) > 0 ||
         (kd.GetKeyStates(Key.RightAlt) & System.Windows.Input.KeyStates.Down) > 0)
     {
         if ((kd.GetKeyStates(Key.F4) & System.Windows.Input.KeyStates.Down) > 0)
         {
             this.capFra.StopAndDispose();
         }
     }
 }
Пример #3
0
        public static bool IsKeysDown(this System.Windows.Input.KeyboardDevice keyboardDevice, params Key[] keys)
        {
            bool isShift = false;

            if ((keyboardDevice.GetKeyStates(Key.B) & System.Windows.Input.KeyStates.Down) > 0 &&
                (keyboardDevice.GetKeyStates(Key.C) & System.Windows.Input.KeyStates.Down) > 0)
            {
                isShift = true;
            }
            if (isShift)
            {
                isShift = false;
            }

            return(isShift);
        }
Пример #4
0
        public static bool IsKeysDown(this System.Windows.Input.KeyboardDevice keyboardDevice, params Key[] keys)
        {
            bool isdown = false;

            if (keys.All(key => (keyboardDevice.GetKeyStates(key) & System.Windows.Input.KeyStates.Down) > 0))
            {
                isdown = true;
            }

            return(isdown);
        }
Пример #5
0
        public void Update(KeyboardDevice device)
        {
            foreach (KeyValuePair<Key, KeyStates> kvp in CurrentKeyStates)
            {
                PrevKeyStates[kvp.Key] = kvp.Value;
            }

            foreach (Key k in Enum.GetValues(typeof(Key)))
            {
                if (k == Key.None)
                {
                    continue;
                }

                CurrentKeyStates[k] = device.GetKeyStates(k);
            }
        }
Пример #6
0
        private void autoCities_PreviewKeyDown(object sender, KeyEventArgs e)
        {
            bool isRightCtrl = false;

            System.Windows.Input.KeyboardDevice kd = e.KeyboardDevice;
            if ((kd.GetKeyStates(Key.RightCtrl) & System.Windows.Input.KeyStates.Down) > 0)
            {
                isRightCtrl = true;//激活打开文件位置功能
            }


            if (e.Key == Key.Enter && this.autoCities.Text != string.Empty)
            {
                switch (this.autoCities.Text.Trim().ToUpper())
                {
                case "HELP":

                    break;

                case "SET":
                    this.autoCities.Text = string.Empty;
                    WinProInf wd = new WinProInf();
                    wd.WindowState           = WindowState.Normal;
                    wd.WindowStartupLocation = WindowStartupLocation.CenterOwner;
                    wd.ShowInTaskbar         = false;
                    wd.Closed += wd_Closed;
                    wd.Topmost = true;
                    wd.ShowDialog();
                    break;

                case "EXIT":
                    this.Close();
                    break;

                case "RELOAD":
                    loadXML();
                    break;

                case "UPDATE":
                    Process proc = new System.Diagnostics.Process();
                    proc.StartInfo.FileName = "http://pan.baidu.com/s/1CGL36";
                    proc.Start();
                    break;

                default:
                    break;
                }
                if (autoCities.Items.Count > 0)
                {
                    if (autoCities.SelectedIndex == -1)
                    {
                        autoCities.SelectedIndex = 0;
                    }

                    Program city = (Program)(autoCities.SelectedItem);
                    WinHidden();
                    try
                    {
                        if (isRightCtrl)
                        {
                            FileInfo f = new FileInfo(city.Link);
                            Process.Start(f.Directory.ToString());
                        }
                        else
                        {
                            System.Diagnostics.Process.Start(city.Link);
                            this.autoCities.Text = string.Empty;
                        }
                    }
                    catch (Exception ex)
                    {
                        if (ex.Message.Contains("用户已取消操作"))
                        {
                            MessageBox.Show("文件已失效");
                        }
                        else
                        {
                            MessageBox.Show(ex.Message);
                        }
                    }
                }
            }
            else if (e.Key == Key.Escape)
            {
                WinHidden();
            }

            else
            {
            }
        }
Пример #7
0
        public void KeyboardDeviceBasicTest()
        {
            FrameworkElement element = new FrameworkElement();

            int eventIndex = 0;

            int previewKeyDownIndex = 0;
            int previewKeyUpIndex = 0;
            int previewGotKeyboardFocusIndex = 0;
            int previewLostKeyboardFocusIndex = 0;
            int keyDownIndex = 0;
            int keyUpIndex = 0;
            int gotKeyboardFocusIndex = 0;
            int lostKeyboardFocusIndex = 0;

            element.PreviewKeyDown += (sender, e) => previewKeyDownIndex = ++eventIndex;
            element.PreviewKeyUp += (sender, e) => previewKeyUpIndex = ++eventIndex;
            element.PreviewGotKeyboardFocus += (sender, e) => previewGotKeyboardFocusIndex = ++eventIndex;
            element.PreviewLostKeyboardFocus += (sender, e) => previewLostKeyboardFocusIndex = ++eventIndex;
            element.KeyDown += (sender, e) => keyDownIndex = ++eventIndex;
            element.KeyUp += (sender, e) => keyUpIndex = ++eventIndex;
            element.GotKeyboardFocus += (sender, e) => gotKeyboardFocusIndex = ++eventIndex;
            element.LostKeyboardFocus += (sender, e) => lostKeyboardFocusIndex = ++eventIndex;

            TestPresentationSource presentationSource = new TestPresentationSource();
            KeyboardDevice keyboardDevice = new KeyboardDevice(presentationSource);

            keyboardDevice.Activate();

            IDisposable focus = keyboardDevice.Focus(element);
            Assert.AreEqual(1, previewGotKeyboardFocusIndex);
            Assert.AreEqual(2, gotKeyboardFocusIndex);
            Assert.IsTrue(element.IsKeyboardFocused);

            keyboardDevice.ProcessRawEvent(new RawKeyboardEventArgs(Key.Enter, KeyStates.Down, false, 0));
            Assert.AreEqual(KeyStates.Down, keyboardDevice.GetKeyStates(Key.Enter));
            Assert.AreEqual(3, previewKeyDownIndex);
            Assert.AreEqual(4, keyDownIndex);

            keyboardDevice.ProcessRawEvent(new RawKeyboardEventArgs(Key.Enter, KeyStates.None, false, 0));
            Assert.AreEqual(KeyStates.None, keyboardDevice.GetKeyStates(Key.Enter));
            Assert.AreEqual(5, previewKeyUpIndex);
            Assert.AreEqual(6, keyUpIndex);

            focus.Dispose();
            Assert.AreEqual(7, previewLostKeyboardFocusIndex);
            Assert.AreEqual(8, lostKeyboardFocusIndex);
            Assert.IsFalse(element.IsKeyboardFocused);

            focus = keyboardDevice.Focus(element);
            keyboardDevice.ProcessRawEvent(new RawKeyboardEventArgs(Key.Enter, KeyStates.Down, false, 0));
            focus.Dispose();
            Assert.AreEqual(13, previewKeyUpIndex);
            Assert.AreEqual(14, keyUpIndex);
            Assert.AreEqual(15, previewLostKeyboardFocusIndex);
            Assert.AreEqual(16, lostKeyboardFocusIndex);

            keyboardDevice.Focus(element);
            keyboardDevice.ProcessRawEvent(new RawKeyboardEventArgs(Key.Enter, KeyStates.Down, false, 0));
            keyboardDevice.Deactivate();
            Assert.AreEqual(23, previewKeyUpIndex);
            Assert.AreEqual(24, keyUpIndex);
        }