1、设置窗体KeyPreview属性为True
2、添加窗体的KeyDown事件
/// <summary>
/// 窗体的keydown事件响应 添加快捷键
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void frmScan_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Space)
{
MessageBox.Show("空格键");
} if (e.KeyCode == Keys.Enter)
{
MessageBox.Show("回车键");
}
}