请问在c#如何输出enter和tab键的ascii码值?

解决方案 »

  1.   

    你是要ascii码值还是keyCode?
    就搞个KeyDown之类的事件做测试呗,在事件中打印或者弹出按键相关的值不就知道了
      

  2.   

     Console.WriteLine((int)Keys.Tab);
                Console.WriteLine((int)Keys.Enter);
      

  3.   

    非常感谢楼上两位的支持,但是2楼提供的方法不行啊,我已经试过了,1楼的回复有点接近,但是能给出具体的代码吗?我是要ascii码值的。谢谢。
      

  4.   

    你右键Keys这个枚举,然后转到定义。就知道了
      

  5.   

    using System;
    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
    */
      

  6.   

    private void textBox3_KeyDown(object sender, KeyEventArgs e)
            {
                textBox3.Text = e.KeyValue.ToString();
            }
      

  7.   

    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);
            }    }
    }