2

My requirement is when ever user pressed Ctrl+Pause in my windows application I want to show some message to user. How to capture Ctrl+Pause in the windows form using Keydown event.

1
  • 1
    Those are keys that are used for console mode apps. A user will never think to press them in a gui app. Don't add undiscoverable features to a program, it is a waste of energy. Dec 21, 2012 at 13:42

2 Answers 2

3

The event handler would look something like this:

void myForm_KeyDown(object sender, KeyEventArgs e)
{
    if(e.KeyCode == Keys.Pause && ModifierKeys == Keys.Control)
    {
      //Code for showing message goes here
    }
}
2
  • 4
    @user1921323 How are we to know what you have tried when you did not show us any effort? And, "it's not working" is not a helpful description of a technical problem. Dec 21, 2012 at 11:20
  • Can you please try and give me the reply. Dec 21, 2012 at 11:42
1

Ctrl+Pause generate special KeyCode: Cancel

void myForm_KeyDown(object sender, KeyEventArgs e)
{
  if(e.KeyCode == Keys.Cancel) //Control + Pause
  {
    //Code for showing message goes here
  }
}
1
  • 1
    This works for WinForms. If anyone is after the equivalent for WPF, the key binding is <KeyBinding Key="Cancel" Modifiers="Control"/>. You need to include the Control modifier.
    – reduckted
    Mar 14, 2017 at 10:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.