---
title: "Check which modifier key is pressed"
description: Learn how to detect when the SHIFT, ALT, or CTRL keys are pressed in Windows Forms for .NET.
ms.date: 10/26/2020
dev_langs:
- "csharp"
- "vb"
helpviewer_keywords:
- "keyboard input"
- "shift keys"
- "events [Windows Forms], mouse"
- "Keys.ControlKey enumeration member"
- "keys [Windows Forms], control keys"
- "user input [Windows Forms], checking for keyboard"
- "keys [Windows Forms], determining last pressed"
- "keys [Windows Forms], shift keys"
- "keys [Windows Forms], modifier keys"
- "control keys"
- "keys [Windows Forms], alt keys"
- "alt keys"
- "Keys.Shift enumeration member"
- "events [Windows Forms], keyboard"
- "keyboards [Windows Forms], keyboard input"
- "Keys.Alt enumeration member"
- "modifier keys"
---
# How to check for modifier key presses (Windows Forms .NET)
As the user types keys into your application, you can monitor for pressed modifier keys such as the SHIFT, ALT, and CTRL. When a modifier key is pressed in combination with other keys or even a mouse click, your application can respond appropriately. For example, pressing the S key may cause an "s" to appear on the screen. If the keys CTRL+S are pressed, instead, the current document may be saved.
[!INCLUDE [desktop guide under construction](../../includes/desktop-guide-preview-note.md)]
If you handle the event, the property received by the event handler specifies which modifier keys are pressed. Also, the property specifies the character that was pressed along with any modifier keys combined with a bitwise OR.
If you're handling the event or a mouse event, the event handler doesn't receive this information. Use the property of the class to detect a key modifier. In either case, you must perform a bitwise AND of the appropriate value and the value you're testing. The enumeration offers variations of each modifier key, so it's important that you do the bitwise AND check with the correct value.
For example, the SHIFT key is represented by the following key values:
-
-
-
-
The correct value to test SHIFT as a modifier key is . Similarly, to test for CTRL and ALT as modifiers you should use the and values, respectively.
## Detect modifier key
Detect if a modifier key is pressed by comparing the property and the enumeration value with a bitwise AND operator.
The following code example shows how to determine whether the SHIFT key is pressed within the and event handlers.
:::code language="csharp" source="snippets/how-to-check-modifier-key/csharp/Form1.cs" id="DetectModifier":::
:::code language="vb" source="snippets/how-to-check-modifier-key/vb/Form1.vb" id="DetectModifier":::
## See also
- [Overview of using the keyboard (Windows Forms .NET)](overview.md)
- [Using keyboard events (Windows Forms .NET)](events.md)
-
-
-
-