Best Python code snippet using fMBT_python
eyenfinger.py
Source:eyenfinger.py  
...1096            press, release = 1, 11097        else:1098            raise ValueError('Invalid keySpec "%s"' % (a,))1099    if inputKeySeq:1100        _writeInputKeySeq(_deviceFilename(device), inputKeySeq, hold=hold, delay=delay)1101def _deviceFilename(deviceName):1102    if not _deviceFilename.deviceCache:1103        _deviceFilename.deviceCache = dict(_listInputDevices())1104    if not deviceName in _deviceFilename.deviceCache:1105        return deviceName1106    else:1107        return _deviceFilename.deviceCache[deviceName]1108_deviceFilename.deviceCache = {}1109def _listInputDevices():1110    nameAndFile = []1111    for l in file("/proc/bus/input/devices"):1112        if l.startswith("N: Name="):1113            nameAndFile.append([l.split('"')[1]])1114        elif l.startswith("H: Handlers=") and "event" in l:1115            try:1116                eventFilename = re.findall("(event[0-9]+)", l)[0]1117                nameAndFile[-1].append("/dev/input/%s" % (eventFilename,))1118            except:1119                _log('WARNING: Could not recognise event[0-9] filename from row "%s".' % (l.strip(),))1120    return nameAndFile1121def _writeInputKeySeq(filename, keyCodeSeq, hold=0.1, delay=0.1):1122    if type(filename) != str or len(filename) == 0:1123        raise ValueError('Invalid input device "%s"' % (filename,))1124    fd = os.open(filename, os.O_WRONLY | os.O_NONBLOCK)1125    for press, release, keyCode in keyCodeSeq:1126        if press:1127            bytes = os.write(fd, struct.pack(_InputEventStructSpec,1128                                             int(time.time()), 0, _EV_KEY, keyCode, 1))1129            if bytes > 0:1130                bytes += os.write(fd, struct.pack(_InputEventStructSpec,1131                                                  0, 0, 0, 0, 0))1132            time.sleep(hold)1133        if release:1134            bytes += os.write(fd, struct.pack(_InputEventStructSpec,1135                                              int(time.time()), 0, _EV_KEY, keyCode, 0))...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!!
