Windows Form 응용 프로그램에서 Form의 KeyDown 이벤트를 사용하여 단축키를 누르면 일부 기능을 실행하려고합니다. 문제는 내가 단축키를 계속 누르면 이벤트가 계속해서 발생한다는 것입니다.Windows Forms KeyDown 이벤트가 계속 발생합니다.
처음 버튼과 다른 기능을 눌렀을 때 몇 가지 기능을 실행하고 싶습니다. 내가 단축키의 무리를 사용하는거야
bool isPressed_Num7 = false;
bool isPressed_Num9 = false;
private void Form1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyData == Keys.NumPad7 && !isPressed_Num7)
{
isPressed_Num7 = true;
Console.WriteLine("Keydown 7");
}
if (e.KeyData == Keys.NumPad9 && isPressed_Num9)
{
isPressed_Num9 = true;
Console.WriteLine("Keydown 9");
}
}
private void Form1_KeyUp(object sender, KeyEventArgs e)
{
if (e.KeyData == Keys.NumPad7)
{
isPressed_Num7 = false;
Console.WriteLine("Keyup 7");
}
if (e.KeyData == Keys.NumPad9)
{
isPressed_Num9 = false;
Console.WriteLine("Keyup 9");
}
}
: 여기
내가이 작업을 수행하는 데 사용되는 코드입니다. 그래서 제가하고 싶은 일을 성취 할 수있는 더 좋은 방법이 있습니까?
[여러 keystokes가 하나 개의 키를 누르에서 수신 할 수있는 방법을하지?] (http://stackoverflow.com/questions/2490771/how-not-to-allow-multiple-keystokes-received-at-one -key-press) –
우리가하려는 일만 알면. –
그가 * 물어 보려고하는 것은 다음과 같습니다. 이벤트 처리기에서 true 및 false로 설정해야하는 모든 키에 대해 변수로 끝내지 않으려면 어떻게해야합니까? – aquinas