2009-12-04 40 views
1

我正在使用zbarcam從我的webapps中的網絡攝像頭讀取條形碼。 但是,由於zbarcam在最後顯示\ n,我的表單被提交。使用xvkbd讀取條形碼。如何禁用Enter鍵?

下面是我用:

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 - 

如何,我不是在發送前刪除 '\ n'條碼到xvkbd或禁用xvkbd中的回車鍵?

回答

1

試試這個:

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

完美,謝謝。 – Natim 2009-12-04 02:17:37

1

要去除輸入:

print symbol.data.strip() 

但pipeable程序,它是一種討厭的。你可以只直接發送從你的程序輸入xvkbd(和不需要的文件,如果你不介意通過在args字符串):

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

這也避免了另一個shell和腳本運行。