我正在制作一个应用程序,用于按键时间识别人物。多数民众赞成我如何衡量时间:
private void Label_KeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.A || e.Key == Key.O)
{
stopwatch.Start();
}
else
{
e.Handled = true;
}
}
private void Label_KeyUp(object sender, KeyEventArgs e)
{
if (e.Key == Key.A)
{
stopwatch.Stop();
string aS = stopwatch.ElapsedMilliseconds.ToString(); //get time of pressing key
int aI = Convert.ToInt32(aS); //string -> int
a += aI; //summary of pressing key
stopwatch.Reset();
aCounter++;
}
if (e.Key == Key.O)
{
stopwatch.Stop();
string oS = stopwatch.ElapsedMilliseconds.ToString();
int oI = Convert.ToInt32(oS);
o += oI;
stopwatch.Reset();
oCounter++;
}
}
我认为我的飞行时间有问题,因为有时特定键的测量值是== 0。如果有任何方法可以帮助我正确处理飞行时间?或许你有一些建议?谢谢你的帮助