How to unregister a specific hotkey using c#

Posted by srk on Stack Overflow See other posts from Stack Overflow or by srk
Published on 2010-06-03T07:58:12Z Indexed on 2010/06/03 8:04 UTC
Read the original article Hit count: 198

Filed under:

I am using the below code to register a HotKey :

RegisterGlobalHotKey(Keys.F4, USE_ALT);

 private void RegisterGlobalHotKey(Keys hotkey, int modifiers)
        {
            try
            {
                // increment the hot key value - we are just identifying
                // them with a sequential number since we have multiples
                mHotKeyId++;

                if (mHotKeyId > 0)
                {
                    // register the hot key combination
                    if (RegisterHotKey(this.Handle, mHotKeyId, modifiers, Convert.ToInt16(hotkey)) == 0)
                    {
                        // tell the user which combination failed to register -
                        // this is useful to you, not an end user; the end user
                        // should never see this application run
                        MessageBox.Show("Error: " + mHotKeyId.ToString() + " - " +
                            Marshal.GetLastWin32Error().ToString(),
                            "Hot Key Registration");
                    }
                }
            }
            catch
            {
                // clean up if hotkey registration failed -
                // nothing works if it fails
                UnregisterGlobalHotKey();
            }
        }

        private void UnregisterGlobalHotKey()
        {
            // loop through each hotkey id and
            // disable it
            for (int i = 0; i < mHotKeyId; i++)
            {
                UnregisterHotKey(this.Handle, i);
            }
        }

How can i unregister the Hot key and Make Alt+ F4 keep working again ?

© Stack Overflow or respective owner

Related posts about c#