【问题标题】:How can I read barcodes without having the user focus a text box first?如何在不让用户先关注文本框的情况下读取条形码?
【发布时间】:2010-04-22 05:47:19
【问题描述】:

我最近购买了 Metrologic 条码扫描仪(USB 端口),众所周知,它可以作为开箱即用的键盘模拟器。

如何配置扫描仪和我的应用程序,以便我的应用程序可以直接处理条形码数据?也就是说,我不希望用户专注于“文本字段”,然后在 KeyPress 事件触发时处理数据。

【问题讨论】:

    标签: c# java windows delphi barcode


    【解决方案1】:

    通常可以将条形码扫描仪配置为在字符串之前和之后发送一些字符。因此,如果您在条形码字符串之前附加例如“F12”,您可以捕获它并将焦点移动到正确的字段。

    查看条形码扫描仪手册如何操作。

    【讨论】:

    • 通常你希望有一个文本字段,以便用户在扫描失败时手动输入条形码。这就是为什么我认为这是最好的选择。
    • 这就是我们使用支票阅读器的方式;无论它们是键盘楔形还是 USB,我们都将它们配置为发送一个不容易在键盘上键入的起始字符序列。当我们通过表单的 keydown 方法看到该序列时,我们会吞下那些特殊的按键并将输入焦点移动到所需的编辑框。效果很好。
    【解决方案2】:

    虽然您的条形码有 USB 连接器。它可以编程为键盘楔形或 RS232。 看到这个页面http://www.instrumentsandequipmentco.com/support/faq-metrologic.htm 哪里写的

    问。 USB 键盘和 USB 销售点有什么区别? 当 MX009 设置为作为 USB 键盘进行通信时,扫描的数据将出现在您 PC 上当前处于活动状态的应用程序中。就像在键盘上按下键一样输入数据。当 MX009 设置为作为 USB 销售点设备进行通信时,数据会像 RS232 数据一样传输到 USB 端口,并且 USB 端口必须像 COM 端口一样配置。 MX009 出厂设置为 USB 键盘或 USB 销售点。

    当您的程序接受 RS232 时,您不再需要将焦点放在文本字段中。

    1. 将您的条形码重新编程为销售点 (RS232)
    2. 重新编程以通常发送后缀 - 回车/CR/$0D 在条形码的末尾。

    查看回车以了解完整条形码何时可用于您的代码。

    【讨论】:

      【解决方案3】:

      我想最简单的方法是拦截更高级别的按键,例如winforms中的PreviewKeyDown(或在表单上使用KeyDown,将KeyPreview设置为true,并使用e.SuppressKeyPress 停止按键向下进入控件)。 可能有设备的直接 API;可能没有。

      【讨论】:

        【解决方案4】:

        您可以在表单上使用 OnShortcut 事件来拦截键盘按下。 检查您在barcodescanner上配置的前缀是否出现,并设置为Handled al keypresses,直到您获得条形码扫描仪后缀。 在您的快捷方式处理程序中构建条形码字符串

        以下代码改编自我自己使用的代码,但未经测试。

            // Variables defined on Form object
        GettingBarcode : boolean;
        CurrentBarcode : string;
        TypedInShiftState: integer; // 16=shift, 17=ctrl, 18=alt
        
        procedure Form1.FormShortCut(var Msg: TWMKey; var Handled: Boolean);
        var
          Character:Char;
        begin
          Character:=Chr(MapVirtualKey(Msg.CharCode,MAPVK_VK_TO_CHAR));
          if GettingBarcode then
          begin
            // Take care of case 
            if (TypedInShiftState<>16) and CharInSet(Character,['A'..'Z']) then
                Character:=Chr(Ord(Character)+32);
            TypedInShiftState:=0;
            // Tab and Enter programmed as suffix on barcode scanner
            if CharInSet(Character,[#9, #13]) then
            begin
              // Do something with your barcode string
              try
                HandleBarcode(CurrentBarcode);
              finally
                CurrentBarcode:='';
                Handled:=true;
                GettingBarcode:=False;
              end;
            end
            else if CharInSet(Character,[#0..#31]) then
            begin
              TypedInShiftState:=Msg.CharCode;
              Handled:=True;
            end
            else begin
              CurrentBarcode:=CurrentBarcode+Character;
              Handled:=true;
            end;
          end
          else begin
            if Character=#0 then
            begin
              TypedInShiftState:=Msg.CharCode;
            end
            else if (TypedInShiftState=18) and (Character='A') then
            begin
              GettingBarcode:=True;
              CurrentBarcode:='';
              Handled:=true;
            end;
          end;
        end;
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2019-12-24
          • 1970-01-01
          • 2011-03-27
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多