Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
  • How to catches all keyboard events in OpenERP(Odoo)

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 635
    Comment on it

    In OpenERP first create custom module and inherits the Scanner object in your own module and pass all the barcode fields and map it to the object.

    Then this barcode will start a loop that catches all keyboard events in Odoo. And by using the parse barcode in your event put them on a timestamped queue. And all barcode consumed in the point of sale module and request to the barcode even.

    Using this function given below:

    def runs_events(self ,cr, uid, id, context=None):
            self.barcodes = Queue()    
            barcode  = []
            shift    = False
            devices  = None
            while True:
                devices = self.get_devices()
                    while True:
                        r,w,x = select({dev.fd: dev for dev in [d.evdev for d in devices]},[],[],5)
                        if len(r) == 0:
                        for fd in r:
                            device = self._get_open_device_by_fd(fd)
                            if not evdev.util.is_device(device.evdev.fn):
                      '%s disconnected', str(device.evdev))
                            events =
                            for event in events:
                                if event.type == evdev.ecodes.EV_KEY:
                                    if event.value == 1:
                                        if event.code in self.keymap:
                                            if device.shift:
                                        elif event.code == 42 or event.code == 54: 
                                            device.shift = True
                                        elif event.code == 28:
                                            _logger.debug('pushing barcode %s from %s', ''.join(device.barcode), str(device.evdev))
                                            self.barcodes.put( (time.time(),''.join(device.barcode)) )
                                            device.barcode = []
                                    elif event.value == 0:
                                        if event.code == 42 or event.code == 54: 
                                            device.shift = False
                except Exception as e:
    scanner_thread = None
    if evdev:
        scanner_thread = Scanner()
        hw_proxy.drivers['scanner'] = scanner_thread

 0 Comment(s)

Sign In

Sign up using

Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: