public void RegisterHotkey(HotkeyInfo hotkeyInfo) { if (hotkeyInfo != null && hotkeyInfo.Status != HotkeyStatus.Registered) { if (!hotkeyInfo.IsValidHotkey) { hotkeyInfo.Status = HotkeyStatus.NotConfigured; return; } if (hotkeyInfo.ID == 0) { string uniqueID = Helpers.GetUniqueID(); hotkeyInfo.ID = NativeMethods.GlobalAddAtom(uniqueID); if (hotkeyInfo.ID == 0) { DebugHelper.WriteLine("Unable to generate unique hotkey ID: " + hotkeyInfo); hotkeyInfo.Status = HotkeyStatus.Failed; return; } } if (!NativeMethods.RegisterHotKey(Handle, hotkeyInfo.ID, (uint)hotkeyInfo.ModifiersEnum, (uint)hotkeyInfo.KeyCode)) { NativeMethods.GlobalDeleteAtom(hotkeyInfo.ID); DebugHelper.WriteLine("Unable to register hotkey: " + hotkeyInfo); hotkeyInfo.ID = 0; hotkeyInfo.Status = HotkeyStatus.Failed; return; } hotkeyInfo.Status = HotkeyStatus.Registered; } }