The key press events include KeyDown, KeyUp, KeyPress. Event handling methods are defined in frmMain class and in InitializeComponent() method:
using System.Windows.Forms; partial class frmMain { private void InitializeComponent() { this.Width = 1000; this.Height = 600; this.KeyPreview = true; this.KeyPress += new KeyPressEventHandler(testButton_KeyPress); this.KeyDown += new KeyEventHandler(testButton_KeyDown); this.FormClosing += new FormClosingEventHandler(testButton_FormClosing); this.components = new System.ComponentModel.Container(); System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(frmMain)); this.openDialog = new System.Windows.Forms.OpenFileDialog(); ... } void testButton_KeyDown(object sender, KeyEventArgs kea) { switch (kea.KeyData) { case Keys.Left: ... break; case Keys.Right: ... break; } } }
List of keycode
: