Capture keyboard event CTRL+S in WPF

I need to fire an event by pressing CTRL+s.To do this create a windows “KeyDown” event like this

<Window x:Class="Testing.MainWindow"
Title="MainWindow" Height="350" Width="525"  KeyDown="Window_KeyDown">

Now use this cs code

private void Window_KeyDown(object sender, KeyEventArgs e)
if (Keyboard.Modifiers == ModifierKeys.Control && e.Key == Key.S)
MessageBox.Show("user is pressed Ctrl+S");

If you have any query please leave a comment.


3 Responses to “Capture keyboard event CTRL+S in WPF”

  1. Nassos Kranidiotis Says:

    Hello. I tried the code you suggested, but it didn’t work for me. When I press Ctrl+S, the Windows_Keydown event captures the Ctrl key pressed; not the S key. No matter how hard I try to press both Ctrl key and S key simultaneously, the result is always the same. Any suggestions?

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: