Question

when i run RegisterHotKey, it returns false. what are possible reasons?

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 (don't judge please)

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");
}
Était-ce utile?

La solution

Seems that your code will always throw exception, try change to below..

    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");
             }
        }
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top