为什么RegisterHotKey返回false? user32.dll中

时间:2014-02-24 00:22:04

标签: c# user32 registerhotkey

当我运行RegisterHotKey时,它返回false。可能的原因是什么?

internal void RegisterHotKey2(ModifierKeys modifier, Keys key)
{
    _cID += 1;
    if (!RegisterHotKey(_window.Handle, _cID, (uint)modifier, (uint)key))
    {
        Console.WriteLine("oh no: " + modifier.ToString() + " + " + key.ToString());
        throw new InvalidOperationException("couldn't register noooooo");
    }
}

OLD VERSION(请勿判断)

internal void RegisterHotKey2(ModifierKeys modifier, Keys key)
{
    _cID += 1;
    if (!RegisterHotKey(_window.Handle, _cID, (uint)modifier, (uint)key))
        Console.WriteLine("oh no: " + modifier.ToString() + " + " + key.ToString());
    throw new InvalidOperationException("couldn't register noooooo");
}

1 个答案:

答案 0 :(得分:1)

似乎您的代码将始终抛出异常,请尝试更改为以下..

    internal void RegisterHotKey2(ModifierKeys modifier, Keys key)
        {
            _cID += 1;
            if (!RegisterHotKey(_window.Handle, _cID, (uint)modifier, (uint)key))
             {
                Console.WriteLine("oh no: " + modifier.ToString() + " + " + key.ToString()); 
                throw new InvalidOperationException("couldn't register noooooo");
             }
        }