Best Python code snippet using pyatom_python
AXClasses.py
Source:AXClasses.py  
...194        if not hasattr(self, 'eventList'):195            self.eventList = deque([(event, args)])196            return197        self.eventList.append((event, args))198    def _addKeyToQueue(self, keychr, modFlags=0, globally=False):199        """Add keypress to queue.200        Parameters: key character or constant referring to a non-alpha-numeric201                    key (e.g. RETURN or TAB)202                    modifiers203                    global or app specific204        Returns: None or raise ValueError exception.205        """206        # Awkward, but makes modifier-key-only combinations possible207        # (since sendKeyWithModifiers() calls this)208        if not keychr:209            return210        if not hasattr(self, 'keyboard'):211            self.keyboard = AXKeyboard.loadKeyboard()212        if keychr in self.keyboard['upperSymbols'] and not modFlags:213            self._sendKeyWithModifiers(keychr,214                                       [AXKeyCodeConstants.SHIFT],215                                       globally)216            return217        if keychr.isupper() and not modFlags:218            self._sendKeyWithModifiers(219                keychr.lower(),220                [AXKeyCodeConstants.SHIFT],221                globally222            )223            return224        if keychr not in self.keyboard:225            self._clearEventQueue()226            raise ValueError('Key %s not found in keyboard layout' % keychr)227        # Press the key228        keyDown = Quartz.CGEventCreateKeyboardEvent(None,229                                                    self.keyboard[keychr],230                                                    True)231        # Release the key232        keyUp = Quartz.CGEventCreateKeyboardEvent(None,233                                                  self.keyboard[keychr],234                                                  False)235        # Set modflags on keyDown (default None):236        Quartz.CGEventSetFlags(keyDown, modFlags)237        # Set modflags on keyUp:238        Quartz.CGEventSetFlags(keyUp, modFlags)239        # Post the event to the given app240        if not globally:241            self._queueEvent(Quartz.CGEventPostToPid, (self._getPid(), keyDown))242            self._queueEvent(Quartz.CGEventPostToPid, (self._getPid(), keyUp))243        else:244            self._queueEvent(Quartz.CGEventPost, (0, keyDown))245            self._queueEvent(Quartz.CGEventPost, (0, keyUp))246    def _sendKey(self, keychr, modFlags=0, globally=False):247        """Send one character with no modifiers.248        Parameters: key character or constant referring to a non-alpha-numeric249                    key (e.g. RETURN or TAB)250                    modifier flags,251                    global or app specific252        Returns: None or raise ValueError exception253        """254        escapedChrs = {255            '\n': AXKeyCodeConstants.RETURN,256            '\r': AXKeyCodeConstants.RETURN,257            '\t': AXKeyCodeConstants.TAB,258        }259        if keychr in escapedChrs:260            keychr = escapedChrs[keychr]261        self._addKeyToQueue(keychr, modFlags, globally=globally)262        self._postQueuedEvents()263    def _sendKeys(self, keystr):264        """Send a series of characters with no modifiers.265        Parameters: keystr266        Returns: None or raise ValueError exception267        """268        for nextChr in keystr:269            self._sendKey(nextChr)270    def _pressModifiers(self, modifiers, pressed=True, globally=False):271        """Press given modifiers (provided in list form).272        Parameters: modifiers list, global or app specific273        Optional: keypressed state (default is True (down))274        Returns: Unsigned int representing flags to set275        """...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!!
