python - Read USB Magstripe reader through ssh -
i made python program pi detects strings usb card reader(it acts usb keyboard) , writes them file. realized if ssh program run it, program not work. guess because program takes raw input typed console, won't work if turn on through ssh. can me on this?
below program:
import datetime import time card = raw_input() t = datetime.datetime.now() while true: f = open("laptop sign out" + '.txt', 'a') f.write("card number: " + card[1:10] + " time: " + t.strftime("%m-%d-%y $ f.write('\n') f.write(';') f.write('\n') f.close() time.sleep(5)
you can use evdev library, allows redirect events generated in kernel directly user code.
look @ example:
>>> evdev import inputdevice, categorize, ecodes >>> dev = inputdevice('/dev/input/event1') >>> print(dev) device /dev/input/event1, name "dell dell usb keyboard", phys "usb-0000:00:12.1-2/input0" >>> event in dev.read_loop(): ... if event.type == ecodes.ev_key: ... print(categorize(event)) ... # pressing 'a' , holding 'space' key event @ 1337016188.396030, 30 (key_a), down key event @ 1337016188.492033, 30 (key_a), key event @ 1337016189.772129, 57 (key_space), down key event @ 1337016190.275396, 57 (key_space), hold key event @ 1337016190.284160, 57 (key_space), additional reading here
a little bit different way described here
Comments
Post a Comment