开发者

How to capture keystrokes with a Python daemon?

开发者 https://www.devze.com 2022-12-16 04:54 出处:网络
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 trying to write a POS-style application for a Sheevaplug that does the following:

  1. Captures input from a card reader (as I understand, most mag card readers emulate keyboard input, so basically I'm looking to capture that)
  2. Doesn't require X
  3. 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.

0

精彩评论

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