ฉันกำลังพยายามสร้างเกมใน Monodevelop โดยใช้ Gtk#-C# โดยให้ผู้เล่นเคลื่อนตัวละครไปรอบๆ ด้วยปุ่มลูกศร อย่างไรก็ตาม การกดปุ่มลูกศรไม่ได้ถูกลงทะเบียน
มีวิธีตรวจจับการกดปุ่มด้วยตนเองโดยข้ามตัวจัดการเริ่มต้นหรือไม่
การค้นหาหลายครั้งทั้งบน 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);
}
และนี่คือโปรแกรมพื้นฐานที่ฉันทำเพื่อพยายามหาวิธีตรวจจับปุ่มลูกศร:
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 ();
}