Best Python code snippet using fMBT_python
fmbtuinput.py
Source:fmbtuinput.py  
...528                 if line.startswith('N: ')][0]529        _g_deviceNames[_name] = ("/dev/input/" +530                                 re.findall('[ =](event[0-9]+)\s', d)[0])531        _g_filenames[_g_deviceNames[_name]] = _name532def toEventFilename(deviceName):533    return _g_deviceNames[deviceName]534def toEventDeviceName(filename):535    return _g_filenames[filename]536class InputDevice(object):537    def __init__(self):538        if not "_g_devices" in globals():539            refreshDeviceInfo()540        self._fd = -1541        self._filename = None542        self._uidev = None543        self._created = False544        self._opened = False545    def __del__(self):546        if self._created:547            self.destroy()548    def startCreating(self, name, vendor, product, version,549                      absmin=None, absmax=None):550        if self._fd > 0:551            raise InputDeviceError("InputDevice is already open")552        self._fd = os.open("/dev/uinput", os.O_WRONLY | os.O_NONBLOCK)553        if absmin == None:554            absmin = [0 for _ in xrange(abs_count)]555        if absmax == None:556            absmax = [0 for _ in xrange(abs_count)]557        absfuzz = [0 for _ in xrange(abs_count)]558        absflat = [0 for _ in xrange(abs_count)]559        self._uidev = struct.pack(struct_uinput_user_dev,560                                  name, # name561                                  BUS_USB, # id.bus_type562                                  vendor, # id.vendor563                                  product, # id.product564                                  version, # id.version565                                  0, # ff_effects_max566                                  # TODO: why absmin + absmax gives567                                  # error for touch?568                                  *(absmax + absmin + absfuzz + absflat)569                              )570    def finishCreating(self):571        if self._fd < 1:572            raise InputDeviceError("startCreating() not called")573        bytes_written = os.write(self._fd, self._uidev)574        if bytes_written != sizeof_uinput_user_dev:575            raise InputDeviceError(576                "Writing to /dev/uinput failed, wrote %s/%s bytes"577                % (bytes_written, sizeof_uinput_user_dev))578        rv = fcntl.ioctl(self._fd, UI_DEV_CREATE)579        if rv != 0:580            raise InputDeviceError(581                "Creating device failed, ioctl UI_DEV_CREATE returned %s"582                % (rv,))583        self._created = True584        return True585    def destroy(self):586        if self._created:587            fcntl.ioctl(self._fd, UI_DEV_DESTROY)588            self._created = False589        self.close()590    def open(self, filename):591        if self._fd > 0:592            raise InputDeviceError("InputDevice is already open")593        if not filename.startswith("/dev/input"):594            filename = toEventFilename(filename)595        self._fd = os.open(filename, os.O_WRONLY | os.O_NONBLOCK)596        self._filename = filename597        self._created = False598        return self599    def close(self):600        if self._fd > 0:601            os.close(self._fd)602            self._fd = -1603    def filename(self):604        return self._filename605    def addCap(self, capBit, capCodeOrName, capCode2Name):606        if self._fd < 1:607            raise InputDeviceError("startCreating() not called")608        if self._created or self._opened:...Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
