tags:

views:

37

answers:

1

I want to detect pressing the "snapshot" button on the top of a webcam in linux. The button has this entry in /dev: /dev/input/by-id/usb-PixArt_Imaging_Inc._USB2.0_UVC_VGA-event-if00

I am using the "rel" wrapper, at the moment, because it handles exceptions better. Before the following code executes, self.s.cam_btn is assigned the /dev entry for the button.

    rel.override()
    rel.init()
    rel.read(self.s.cam_btn, self.snap)
    rel.dispatch()

self.snap() is the callback. It captures a screen shot from mplayer and feeds the image to an OCR program. Everything mostly works until the callback returns. Here is the problem:

If self.snap() returns nothing, the program stops and will not service any more button events. If self.snap() returns 1, the program continues servicing the same button event in an infinite loop, rather than waiting for a new event. Documentation for pyevent is a little sparse so any help gratefully received.

Clinton

A: 

Never used pyevent, but would try rescheduling the event at the end of the handler:

def snap(self):
    # ... code ...
    rel.read(self.s.cam_btn, self.snap)
    return False
nosklo