How to capture keystrokes using Python daemon?

I am trying to write a POS style application for Sheevaplug that does the following:

  • It captures input from a card reader (as I understand it, most magnetic card readers emulate keyboard input, so basically I'm looking for this)
  • Not required x
  • Running in the background (daemon)

I saw examples of code that STDIN will wait for, but this will not work, because it is a background process without logging in, not even a monitor.

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, being closest to what I need, generates only a series of numbers, all of which are different from each other, and I don’t know how to translate them into useful values.

It’s clear that I missed something here, but I don’t know what it is. Can someone please how to get the rest of the way?

+4
source share
2 answers

Section 5 of the Linux kernel input documentation describes what each of the values ​​in the event interface means.

+2
source

the format is explained in the documentation in section 5. Event interface.

+1
source

All Articles