Posts

Showing posts with the label keyevent

C# Key Events - KeyDown

Image
Clash Royale CLAN TAG #URR8PPP C# Key Events - KeyDown I have a Windows Form Application. I want some functions to work with the space key. But when I press the space key, the function I want is not working and it goes to the next form. (I did KeyPreview = true) private void Form7_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Space) { IEyeTracker eyeTracker = EyeTrackingOperations.FindAllEyeTrackers().FirstOrDefault(); GazeDataStop(eyeTracker); } } 1 Answer 1 Because: 1- If you have buttons, ... keydown won't work as form won't have focus anymore 2-you must handle the keydown so that it is not passed to ohter controls Solution for 1: set KeyPreview property of your form to true KeyPreview Solution for 2: set e.Handled = true : e.Handled = true private void Form7_KeyDown(object sender, KeyEventArgs e) { e.Ha...