123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Input;
- namespace PDF_Master.Helper
- {
-
- public static class KeyEventsHelper
- {
- #region Todo 快捷键绑定解绑在其他地方使用
-
-
- #endregion Todo 快捷键绑定解绑在其他地方使用
- public static event EventHandler<KeyEventArgs> KeyDown;
- private static KeyEventArgs args;
- static KeyEventsHelper()
- {
- EventManager.RegisterClassHandler(typeof(Window), UIElement.KeyDownEvent, (KeyEventHandler)onKeyDown);
- EventManager.RegisterClassHandler(typeof(ContextMenu), UIElement.KeyDownEvent, (KeyEventHandler)onKeyDown);
- }
- private static void onKeyDown(object sender, KeyEventArgs e)
- {
- if (e != null)
- {
- args = e;
- KeyDown?.Invoke(sender, e);
- }
- }
-
-
-
- public static bool IsSingleKey(Key currentkey)
- {
- if(args == null) return false;
- if (args.Key == currentkey && args.KeyboardDevice.Modifiers == ModifierKeys.None)
- {
- return true;
- }
- return false;
- }
-
-
-
-
- public static bool IsModifierKey(ModifierKeys modifier, Key currentkey)
- {
- if (args == null) return false;
- if (args.Key == currentkey && args.KeyboardDevice.Modifiers == modifier)
- {
- return true;
- }
- return false;
- }
-
-
-
- public static bool IsKeyDown(Key currentkey)
- {
- if (args == null) return false;
- if (Keyboard.IsKeyDown(currentkey))
- {
- return true;
- }
- return false;
- }
-
-
-
- public static bool IsKeyDown(List<Key> keys)
- {
- if (args == null || keys == null || keys.Count > 0) return false;
- bool result = false;
- foreach (Key key in keys)
- {
- result |= Keyboard.IsKeyDown(key);
- }
- if (result)
- {
- return true;
- }
- return false;
- }
- }
- }
|