Files
Andy De George c0ba284473 Initial winforms content migrated (#18)
* Merge winforms framework content to working branch (#14)

* Breadcrumb / TOC / Move net5 to net folder (#15)

* change path from net5 to net

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Add .net 5 winforms placeholder article (#16)

* added some metadata and adjusted net5 placeholder

* corrections

* corrections

* corrections

* Test1

* Swapping landing page vs concept

* fix links

* Fix links

* Fix desc
2020-09-01 16:26:21 -07:00

4.4 KiB

title, ms.date, helpviewer_keywords, ms.assetid
title ms.date helpviewer_keywords ms.assetid
Using Keyboard Events 03/30/2017
KeyPress event [Windows Forms]
keyboards [Windows Forms], keyboard events
KeyUp event
KeyDown event
keyboard events
events [Windows Forms], keyboard
d3f3e14b-a459-4ee6-9875-8957e34f8ee9

Using Keyboard Events

Most Windows Forms programs process keyboard input by handling the keyboard events. This topic provides an overview of the keyboard events, including details on when to use each event and the data that is supplied for each event. Also see Event Handlers Overview (Windows Forms) and Events Overview (Windows Forms).

Keyboard Events

Windows Forms provides two events that occur when a user presses a keyboard key and one event when a user releases a keyboard key:

When a user presses a key, Windows Forms determines which event to raise based on whether the keyboard message specifies a character key or a physical key. For more information about character and physical keys, see How Keyboard Input Works.

The following table describes the three keyboard events.

Keyboard event Description Results
xref:System.Windows.Forms.Control.KeyDown This event is raised when a user presses a physical key. The handler for xref:System.Windows.Forms.Control.KeyDown receives:

xref:System.Windows.Forms.Control.KeyPress This event is raised when the key or keys pressed result in a character. For example, a user presses SHIFT and the lowercase "a" keys, which result in a capital letter "A" character. xref:System.Windows.Forms.Control.KeyPress is raised after xref:System.Windows.Forms.Control.KeyDown.

  • The handler for xref:System.Windows.Forms.Control.KeyPress receives:
  • A xref:System.Windows.Forms.KeyPressEventArgs parameter, which contains the character code of the key that was pressed. This character code is unique for every combination of a character key and a modifier key.

    For example, the "A" key will generate:

    • The character code 65, if it is pressed with the SHIFT key
    • Or the CAPS LOCK key, 97 if it is pressed by itself,
    • And 1, if it is pressed with the CTRL key.
xref:System.Windows.Forms.Control.KeyUp This event is raised when a user releases a physical key. The handler for xref:System.Windows.Forms.Control.KeyUp receives:

See also