因此,我试图用OpenTK来检测关键字,在他们的教程中给出了以下代码:
protected override void OnUpdateFrame(FrameEventArgs args)
{
//Get the state of the keyboard this frame
KeyboardState input = OpenTK.Input.Keyboard.GetState();
if (input.IsKeyDown(Key.Escape))
{
Exit();
}
base.OnUpdateFrame(args);
}但是所发生的情况是,它在"Keyboard.GetState()“处出现了一个错误。错误说:“名称空间'OpenTK.Input‘中不存在类型或名称空间名称’键盘‘(您缺少程序集引用吗?)”。或者,如果我不添加'OpenTK.Input',它将不允许我导入任何东西。
对于"Key.Escape“和"Exit()”,我也有同样的问题
发布于 2022-07-07 15:46:14
好的,我用KeyboardState.IsKeyDown(Keys.Space)解决了这个问题。有了这个,我可以获得空间输入。如果需要任何其他键,则更改"Keys“类函数。
这方面的一个例子是:
protected override void OnUpdateFrame(FrameEventArgs args)
{
if (KeyboardState.IsKeyDown(Keys.Space))
{
Console.WriteLine("Somebody once told me");
}else if (KeyboardState.IsKeyDown(Keys.Escape))
{
this.Close();
}
base.OnUpdateFrame(args);
}如您所见,"Exit()“也被"Close()”替换!
https://stackoverflow.com/questions/72888596
复制相似问题