I want to use the combination Alt+X to close the current form, but there is also one condition: if the user presses a similar combination like Alt+X,C, it shouldn't work.
Asked
Active
Viewed 266 times
0
-
Possible duplicate of [Capture combination key event in a Windows Forms application](https://stackoverflow.com/questions/3062587/capture-combination-key-event-in-a-windows-forms-application) – michal krzych Sep 24 '17 at 16:21
-
Do you want this shortcut within a particular control or the entire application? – hl3mukkel Sep 24 '17 at 16:24
-
particular control – WhiteRaven Sep 24 '17 at 16:30
-
1Alt+X, C are *two* keystrokes. You would have to start a Timer when you see Alt+X to wait for the C to appear. Setting the Interval for this Timer to a suitable value is near impossible. Make it too short and the user loses badly, having the UI go up in smoke. The more the user is impaired, the worse he loses. Make it too long and the user is greatly confuzzled why Alt+X does not appear to work well. Don't do this. – Hans Passant Sep 24 '17 at 17:25
1 Answers
0
The form/control has an event called key press and key down. In the properties window input 'Form1_KeyPress'. This will run the method below
void Form1_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == //KeyCode for alt && e.KeyChar == //KeyCode for x)
{
//run code here
}
}