【问题标题】:Using xvkbd to read a barcode. How to disable Enter key?使用 xvkbd 读取条形码。如何禁用 Enter 键?
【发布时间】:2010-12-23 02:25:39
【问题描述】:

我正在使用 zbarcam 从我的网络应用程序中的网络摄像头读取条形码。 但是,由于 zbarcam 在最后显示一个 \n,我的表单是提交。

这是我使用的:

read_one.py

#!/usr/bin/python
from sys import argv
import zbar
import webbrowser

# create a Processor
proc = zbar.Processor()

# configure the Processor
proc.parse_config('enable')

# initialize the Processor
device = '/dev/video0'
if len(argv) > 1:
    device = argv[1]
proc.init(device)

# enable the preview window
proc.visible = True

# read at least one barcode (or until window closed)
proc.process_one()

# hide the preview window
proc.visible = False

# extract results
for symbol in proc.results:
    # do something useful with results
    print symbol.data

keyboard.sh

python read_one.py | xvkbd -file -

如何在将条形码发送到 xvkbd 之前删除“\n”或禁用 xvkbd 中的回车键?

【问题讨论】:

    标签: python bash barcode barcode-scanner


    【解决方案1】:

    试试这个:

    printf "$(python read_one.py)" | xvkbd -file -
    

    【讨论】:

      【解决方案2】:

      去除输入:

      print symbol.data.strip()
      

      但是这样的管道程序有点讨厌。您可以直接从您的程序发送到 xvkbd(如果您不介意在 args 中传递字符串,则不需要文件):

      import subprocess # at appropriate place
      subprocess.call(['xvkbd', '-text', symbol.data.strip()])
      

      这也避免了运行另一个 shell 和脚本。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-06-24
        • 1970-01-01
        • 2012-01-27
        • 2011-06-16
        • 1970-01-01
        • 2020-01-27
        • 1970-01-01
        • 2022-01-09
        相关资源
        最近更新 更多