"Morten Wennevik" <
[email protected]> a écrit dans le message de Well, Mathieu,
If you use Visual Studio, doubleclick the keydown event for the parent
form. It will typically create something like this
private void Form1_KeyDown(object sender,
System.Windows.Forms.KeyEventArgs e)
{
}
Or you can do it manually, in which case you need to add the line:
this.KeyDown += new
System.Windows.Forms.KeyEventHandler(this.Form1_KeyDown);
in the form's constructor.
Or you can override the keydown on the parent form using
protected override OnKeyDown(System.Windows.Forms.KeyEventArgs e)
{
}
Then put the code checking inside
private void Form1_KeyDown(object sender,
System.Windows.Forms.KeyEventArgs e)
{
if(e.KeyCode == Keys.Escape)
MessageBox.Show("ESCAPE");
if(e.KeyCode == Keys.Z && e.Control)
MessageBox.Show("CTRL-Z");
}
Oki.
Then of course, if the job you want to cancel is happening in the same
thread, hitting any key combination won't work until the job is finished.
Unless you at regular intervals in your heavy duty working code check for
new events. Better yet is to put this code in a separate thread.