'Get the keyboard device.'

def _get_keyboard_device(self):

    from evdev import InputDevice, list_devices
    if self.device_name:
        devices = [InputDevice(file_name) for file_name in list_devices()]
        for device in devices:
            if (self.device_name == device.name):
                return device
    elif self.device_descriptor:
        try:
            device = InputDevice(self.device_descriptor)
        except OSError:
            pass
        else:
            return device
    return None
