程序中有个页面生成条码打印出来,然后通过扫描枪将条码扫描出来,输入到另一个页面的文本框中,进行查询数据。但问题是,扫描枪只要有光标定到可输入的文本框中就会将数据输入到那个文本框中,我想要的是,只要有条码经过扫描枪扫描过我就会自动跳到指定的页面然后在指定的文本框中输入扫描出来的数据。进行查询。

解决方案 »

  1.   

    我可以通过程序获取到按键,但是我测了一下,扫描枪是先将数据输入到你的光标位置,然后才会触发按键比如Enter回车键
      

  2.   

    SerialPort类,希望可以帮到你。
      

  3.   

    楼主这个问题,有一种解决方法,你需要更改条码枪规则,操作方法请看条码枪的说明书(有一本小册子上记录了许多配置条码)原理: 条码枪每次扫描前让它加上一个前缀字符,你在程序中过滤键盘消息专门拦截这个字符,然后跳到你指定的页面。将拦到的字符串放到textbox中.否则别无它法  完毕。 
      

  4.   

    是asp.net还是winform,winform好办,
      

  5.   

    stonespace 老兄,Winform下的话该如何处理呢?
      

  6.   

    把窗体或页面上的所有能接收键盘事件的控件,将其keydown事件注册到窗体或页面上,然后在窗体或页面上的keydown事件去处理,
      

  7.   

    已解决此问题,我的做法如下。
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
     
    namespace Common
    {
        public partial class FrmMain : Form
        {
            BardCodeHooK BarCode = new BardCodeHooK();
            public FrmMain()
            {
                InitializeComponent();
                BarCode.BarCodeEvent += new BardCodeHooK.BardCodeDeletegate(BarCode_BarCodeEvent);
            }
     
            private delegate void ShowInfoDelegate(BardCodeHooK.BarCodes barCode);
            private void ShowInfo(BardCodeHooK.BarCodes barCode)
            {
                if (this.InvokeRequired)
                {
                    this.BeginInvoke(new ShowInfoDelegate(ShowInfo), new object[] { barCode });
                }
                else
                {
                    textBox1.Text = barCode.KeyName;
                    textBox2.Text = barCode.VirtKey.ToString();
                    textBox3.Text = barCode.ScanCode.ToString();
                    textBox4.Text = barCode.Ascll.ToString();
                    textBox5.Text = barCode.Chr.ToString();
                    textBox6.Text = barCode.IsValid? barCode.BarCode : "";//是否为扫描枪输入,如果为true则是 否则为键盘输入
                    textBox7.Text += barCode.KeyName;
                    //MessageBox.Show(barCode.IsValid.ToString());
                }
            }
     
            //C#中判断扫描枪输入与键盘输入         //Private DateTime _dt = DateTime.Now;  //定义一个成员函数用于保存每次的时间点
            //private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
            //{
            //    DateTime tempDt = DateTime.Now;          //保存按键按下时刻的时间点
            //    TimeSpan ts = tempDt .Subtract(_dt);     //获取时间间隔
            //    if (ts.Milliseconds > 50)                           //判断时间间隔,如果时间间隔大于50毫秒,则将TextBox清空
            //        textBox1.Text = "";
            //    dt = tempDt ;
            //}
     
     
     
            void BarCode_BarCodeEvent(BardCodeHooK.BarCodes barCode)
            {
                ShowInfo(barCode);
            }
     
            private void FrmMain_Load(object sender, EventArgs e)
            {
                BarCode.Start();
            }
     
            private void FrmMain_FormClosed(object sender, FormClosedEventArgs e)
            {
                BarCode.Stop();
            }
     
            private void textBox6_TextChanged(object sender, EventArgs e)
            {
                if (textBox6.Text.Length > 0)
                {
                    MessageBox.Show("条码长度:" + textBox6.Text.Length + "\n条码内容:" + textBox6.Text, "系统提示");
                }
            }
        }
    }
      

  8.   

    BardCodeHooK 这个是哪来的?