我正在尝试使用Gtk#-C#在Monodevelop中制作游戏,其中玩家使用箭头键移动角色.但是,箭头键按下没有注册.
有没有办法手动检测按键,绕过默认处理程序?
Google和Stack Overflow上的多次搜索都没有给出如何使用Gtk-C#检测箭头键的答案.
这是我用来尝试检测箭头键的代码:
protected void Key_Press (object obj, KeyPressEventArgs args)
{
//Let the rest of the program know what keys were pressed.
if (pressedKeys.Contains (args.Event.Key))
return;
pressedKeys.Add (args.Event.Key, args.Event.Key);
}
Run Code Online (Sandbox Code Playgroud)
这是我尝试找出如何检测箭头键的基本程序:
public MainWindow (): base (Gtk.WindowType.Toplevel)
{
Build ();
this.KeyPressEvent += new KeyPressEventHandler (KeyPress);
}
protected void KeyPress (object sender, KeyPressEventArgs args)
{
if (args.Event.Key == Gdk.Key.Up)
return;
label1.Text = args.Event.Key.ToString ();
}
Run Code Online (Sandbox Code Playgroud)