KeyDown event not Working on PrintScreen Key

2020-04-02 17:30发布

I am using C# windows Application

I am checking which key, user have pressed down by keyboard. I have checked for all keys but its not working in case of printScreen

private void comboBox1_KeyDown(object sender, KeyEventArgs e)
{
        MessageBox.Show(e.KeyCode.ToString());
}

So how to detect PrintScreen Key

4条回答
成全新的幸福
2楼-- · 2020-04-02 18:12

You can use KeyUp, It captures PrintScreen key.

查看更多
ら.Afraid
3楼-- · 2020-04-02 18:12

You can use

e.Key == Key.Snapshot

This will work on KeyUp event

查看更多
神经病院院长
4楼-- · 2020-04-02 18:21

If the KeyUp event still does not work try modifying the forms KeyPreview property to true, then test the the KeyUp event again.

查看更多
神经病院院长
5楼-- · 2020-04-02 18:33

The print-screen key is trapped by the OS before it is sent to applications. To detect such keys, you need to use a keyboard hook. You may be interested in this article: Low-level Windows API hooks from C# to stop unwanted keystrokes

查看更多
登录 后发表回答