错误:使用C#无法注册热键 [英] Error : Could not register Hot Key using c#

查看:374
本文介绍了错误:使用C#无法注册热键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用下面的代码来注册使用C#热键。但有时我得到的异常抛出无法注册的热键。什么将是此错误的原因是什么?而对于不是一致的。我该如何处理呢?



 公共无效RegisterHotKey(ModifierKeys修改,按键键)
{
/ /计数器递增。
_currentId = _currentId + 1;

//注册的热键。
如果(!RegisterHotKey(_window.Handle,_currentId,(UINT)改性剂,(UINT)键))
抛出新的InvalidOperationException异常(无法注册的热键。);
}


解决方案

阅读MSDN描述RegisterHotKey我碰到:



RegisterHotKey如果热键指定的按键已经被另一个热键注册失败



参考


I am using the below code to register hotkeys using c#. But sometimes i get the exception throwing "Couldn’t register the hot key." What will be the reason for this error ? And for not being consistent. How can i handle this ?

     public void RegisterHotKey(ModifierKeys modifier, Keys key)
    {
            // increment the counter.
            _currentId = _currentId + 1;

            // register the hot key.
            if (!RegisterHotKey(_window.Handle, _currentId, (uint)modifier, (uint)key))
                throw new InvalidOperationException("Couldn’t register the hot key.");
    }

解决方案

Reading the MSDN description for RegisterHotKey I came across:

RegisterHotKey fails if the keystrokes specified for the hot key have already been registered by another hot key.

Ref

这篇关于错误:使用C#无法注册热键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆