我使用RegisterHotKey的方法,实现了全局热键的功能,具体借鉴方法为:https://blog.csdn.net/weixin_44879611/article/details/103275347。
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool RegisterHotKey(IntPtr hWnd, int id, HotkeyModifiers fsModifiers, uint vk);
[DllImport("user32.dll")]
static extern bool UnregisterHotKey(IntPtr hWnd, int id);
现在有个需求,就是需要按键松开时,恢复到之前的状态。
HotKeys.Regist(Application.Current.MainWindow, HotkeyModifiers.MOD_ALT, Key.D1, () =>
{
ServiceLocator.Current.GetInstance<MainMaskModel>().RunService.LetMaskUnvisible();
});
我的操作逻辑时,当键盘上按下并保持按下ALT+1状态时,遮罩层隐藏(执行LetMaskUnvisible函数),当松开两者中任何一个按键时,遮罩层又会出现。
这个该用RegisterHotKey方法怎么解决呢,还是用其他方法更方便一些?