How to capture keystrokes with a Python daemon?
I'm trying to write a POS-style application for a Sheevaplug that does the following:
- Captures input from a card reader (as I understand, most mag card readers emulate keyboard input, so basically I'm looking to capture that)
- Doesn't require X
- Runs in the background (daemon)
I've seen examples of code that will wait for STDIN, but that won't work because this is a background process with no login, not even a monitor actually.
I also found this snippet elsewhere on this site:
from struct import unpack
port = open("/dev/input/event1","rb")
while 1:
a,b,c,d = unpack("4B",port.read(4))
print a,b,c,d
Which, while being the closest thing to what I need so far, only generates a series of numbers, all of which are different with no way that I know of to translate them into useful values.
Clearly, I'm missing something here, but I don't know what it is. Can开发者_StackOverflow someone please how to get the rest of the way?
Section 5 of the Linux kernel input documentation describes what each of the values in the event interface means.
the format is explained in the kernel documentation in section 5. Event Interface.
精彩评论