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
    • 229
    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()
                try:
                    while True:
                        r,w,x = select({dev.fd: dev for dev in [d.evdev for d in devices]},[],[],5)
                        if len(r) == 0:
                            break
                        for fd in r:
                            device = self._get_open_device_by_fd(fd)
                            if not evdev.util.is_device(device.evdev.fn):
                                _logger.info('%s disconnected', str(device.evdev))
                                self.release_device(device)
                                break
                            events = device.evdev.read()
                            for event in events:
                                if event.type == evdev.ecodes.EV_KEY:
                                    if event.value == 1:
                                        if event.code in self.keymap:
                                            if device.shift:
                                                device.barcode.append(self.keymap[event.code][1])
                                            else:
                                                device.barcode.append(self.keymap[event.code][0])
                                        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:
                    self.set_status('error',str(e))
    scanner_thread = None
    if evdev:
        scanner_thread = Scanner()
        hw_proxy.drivers['scanner'] = scanner_thread
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
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: