How to unregister a specific hotkey using c#
- by srk
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 ?