Пример #1
0
        /// <summary>
        ///     Check if a specified Hotkey is available
        /// </summary>
        /// <param name="form">owning form</param>
        /// <param name="key">hot key Key</param>
        /// <param name="modifier">hoy key Modifier</param>
        /// <returns>true if available</returns>
        public static bool IsHotkeyAvailable(Form form, Keys key, WinAPI.KeyModifiers modifier)
        {
            var available = WinAPI.RegisterHotKey(form.Handle, 0, modifier, key);

            if (available)
            {
                WinAPI.UnregisterHotKey(form.Handle, 0);
            }
            return(available);
        }
Пример #2
0
        /// <summary>
        ///     Set up the hook into Windows
        /// </summary>
        protected void Hook()
        {
            for (var i = 0; i < m_hooked.Count; i++)
            {
                var auth     = m_hooked[i];
                var key      = (Keys)auth.HotKey.Key;
                var modifier = auth.HotKey.Modifiers;

                if (WinAPI.RegisterHotKey(m_form.Handle, i + 1, modifier | WinAPI.KeyModifiers.NoRepeat, key) == false)
                {
                    // the MOD_NOREPEAT flag is not support in XP or 2003 and we should get a fail, so we call again without it
                    WinAPI.RegisterHotKey(m_form.Handle, i + 1, modifier, key);
                }
            }
        }