Type of issue
Other (describe below)
Description
This article says that KeyDown occurs only once when a key is held down, however both KeyDown and KeyPress repeat in that case.
- The KeyDown event occurs once.
- The KeyPress event, which can occur multiple times when a user holds down the same key.
The related overview article also implies the same thing.
- The user pushes the A key, the key is preprocessed, dispatched, and a KeyDown event occurs.
- The user holds the A key, the key is preprocessed, dispatched, and a KeyPress event occurs. This event occurs multiple times as the user holds a key.
Handling User Input is also incorrect.
Raised only when a key is initially pressed.
Documentation of the actual behavior is a bit hard to come by, but KeyEventArgs has it right. In any event, it can easily be demonstrated:
var f = new System.Windows.Forms.Form();
f.KeyDown += (sender, e) => System.Diagnostics.Debug.WriteLine("KeyDown");
f.KeyPress += (sender, e) => System.Diagnostics.Debug.WriteLine("KeyPress");
f.KeyUp += (sender, e) => System.Diagnostics.Debug.WriteLine("KeyUp===========");
f.ShowDialog();
Output:
KeyDown
KeyPress
KeyDown
KeyPress
KeyDown
KeyPress
KeyUp===========
Page URL
https://learn.microsoft.com/en-us/dotnet/desktop/winforms/input-keyboard/events
Content source URL
https://github.com/dotnet/docs-desktop/blob/main/dotnet-desktop-guide/winforms/input-keyboard/events.md
Document Version Independent Id
6038a7fc-5a6f-06f9-ad06-dc7039c9909a
Platform Id
c9e78e28-c74b-fde5-a9df-e3e2b96001b3
Article author
@adegeo
Metadata
- ID: 6038a7fc-5a6f-06f9-ad06-dc7039c9909a
- PlatformId: c9e78e28-c74b-fde5-a9df-e3e2b96001b3
- Service: dotnet-desktop
- Sub-service: winforms
Related Issues
Type of issue
Other (describe below)
Description
This article says that KeyDown occurs only once when a key is held down, however both KeyDown and KeyPress repeat in that case.
The related overview article also implies the same thing.
Handling User Input is also incorrect.
Documentation of the actual behavior is a bit hard to come by, but KeyEventArgs has it right. In any event, it can easily be demonstrated:
Output:
Page URL
https://learn.microsoft.com/en-us/dotnet/desktop/winforms/input-keyboard/events
Content source URL
https://github.com/dotnet/docs-desktop/blob/main/dotnet-desktop-guide/winforms/input-keyboard/events.md
Document Version Independent Id
6038a7fc-5a6f-06f9-ad06-dc7039c9909a
Platform Id
c9e78e28-c74b-fde5-a9df-e3e2b96001b3
Article author
@adegeo
Metadata
Related Issues