using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms;namespace 键盘相关 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } protected override void OnKeyDown(KeyEventArgs e) { int index = Convert.ToInt32(e.KeyCode); MessageBox.Show(index.ToString()); base.OnKeyDown(e); } } }
就搞个KeyDown之类的事件做测试呗,在事件中打印或者弹出按键相关的值不就知道了
Console.WriteLine((int)Keys.Enter);
using System.Text.RegularExpressions;class Test
{
static void Main()
{
Console.WriteLine("Tab: {0}", (int)'\t');
Console.WriteLine("Enter: {0}", (int)'\r');
Console.WriteLine("NewLine: {0}", (int)'\n');
}
}
/*
程序输出:
Tab: 9
Enter: 13
NewLine: 10
*/
{
textBox3.Text = e.KeyValue.ToString();
}
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;namespace 键盘相关
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} protected override void OnKeyDown(KeyEventArgs e)
{
int index = Convert.ToInt32(e.KeyCode); MessageBox.Show(index.ToString());
base.OnKeyDown(e);
} }
}