Listen to keyboard shortcuts (C #)

How can I run a method when someone used a keyboard shortcut like Ctrl+ G?

An application is a Windows forms application, and I only want to capture it when the form is activated.

+3
source share
2 answers

Key shortcuts are often called "command keys." If you want the first crack of keystrokes (before your child control), it is best to override the ProcessCmdKey method in your form.

+4
source

Look at your OnKeyPress method on the form or KeyPress event for the form.

Override OnKeyPress like this ...

protected override void OnKeyPress(KeyPressEventArgs e) { ... }

... KeyPressEventArgs, , , Ctrl.

SO , KeyPress... "Ctrl" keydown #

+1

Source: https://habr.com/ru/post/1763178/


All Articles