设置Form的
KeyPreview = true;
在本窗口都可以获得组合和按键
用比如
Form1.KeyDown += Form1_KeyDown;
Form1.KeyUp += Form1_KeyUp;
private static void Form1_KeyDown(object sender, KeyEventArgs e)
{
if (e.Alt && e.KeyCode == Keys.X) // alt-x
{
........
}
}
private static void Form1_KeyUp(object sender, KeyEventArgs e)
{
if ((e.Control && e.KeyCode == Keys.Right) || (e.Control && e.KeyCode == Keys.Left) || (e.Control && e.KeyCode == Keys.Up) || (e.Control && e.KeyCode == Keys.Down) ||
(e.Shift && e.KeyCode == Keys.Right) || (e.Shift && e.KeyCode == Keys.Left) || (e.Shift && e.KeyCode == Keys.Up) || (e.Shift && e.KeyCode == Keys.Down))
{
............
}
}
等等。。。。
不受组件影响,在页面随时取
[此贴子已经被作者于2021-9-23 11:21编辑过]