--- title: "Handle keyboard input at the Form level" description: Learn how to handle keyboard input for your Windows Forms at the form level, before messages reach a control. ms.date: 10/26/2020 dev_langs: - "csharp" - "vb" helpviewer_keywords: - "keyboard input [Windows Forms], at form level" - "Windows Forms, handling keyboard input" - "keyboards [Windows Forms], form-level input" --- # How to handle keyboard input messages in the form (Windows Forms .NET) Windows Forms provides the ability to handle keyboard messages at the form level, before the messages reach a control. This article shows how to accomplish this task. [!INCLUDE [desktop guide under construction](../../includes/desktop-guide-preview-note.md)] ## Handle a keyboard message Handle the or event of the active form and set the property of the form to `true`. This property causes the keyboard to be received by the form before they reach any controls on the form. The following code example handles the event by detecting all of the number keys and consuming 1, 4, and 7. :::code language="csharp" source="snippets/how-to-handle-forms/csharp/Form1.cs" id="HandleKey"::: :::code language="vb" source="snippets/how-to-handle-forms/vb/Form1.vb" id="HandleKey"::: ## See also - [Overview of using the keyboard (Windows Forms .NET)](overview.md) - [Using keyboard events (Windows Forms .NET)](events.md) - - - -