开发者

Using xvkbd to read a barcode. How to disable Enter key?

I am using zbarcam to read barcode from a webcam in my webapps. But, since zbarcam display a \n at the end, my form is submit.

Here is what I use :

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 -

How can I either remo开发者_JAVA百科ve the '\n' before sending the barcode to xvkbd or disable the enter key in xvkbd ?


Try this:

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


To strip the enter:

print symbol.data.strip()

But a pipeable program that does that is kind of nasty. You could just send directly to xvkbd from your program (and no need for file if you don't mind passing the string in args):

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

This also avoids another shell and script to run.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜