开发者

C# Windows Form: How to capture Capture Function, Arrow & Navigation Keys

开发者 https://www.devze.com 2023-02-17 16:07 出处:网络
i am trying to capture Function keys F1 to F12 & 4 Arrow Ke开发者_运维百科ys & Home, Insert, Delete, End, Page Up & Down Keys. How To ????

i am trying to capture Function keys F1 to F12 & 4 Arrow Ke开发者_运维百科ys & Home, Insert, Delete, End, Page Up & Down Keys. How To ????

private void Form1_KeyPress(object sender, KeyPressEventArgs e)
{
}


Override the ProcessCmdKey() method of the form. It gets called straight from the message loop, before the keyboard message is dispatched to the control with the focus. Which is why overriding WndProc() doesn't work.

    protected override bool ProcessCmdKey(ref Message msg, Keys keyData) {
        if (keyData == (Keys.Control | Keys.F)) {
            MessageBox.Show("What the Ctrl+F?");
            return true;
        }
        return base.ProcessCmdKey(ref msg, keyData);
    }

Technically, you can also override the form's OnKeyDown method with KeyPreview = true, but that's an ugly VB6 anachronism.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号