How to use _clearEventQueue method in pyatom

Best Python code snippet using pyatom_python

AXClasses.py

Source:AXClasses.py Github

copy

Full Screen

...182 while len(self.eventList) > 0:183 (nextEvent, args) = self.eventList.popleft()184 nextEvent(*args)185 time.sleep(interval)186 def _clearEventQueue(self):187 """Clear the event queue."""188 if hasattr(self, 'eventList'):189 self.eventList.clear()190 def _queueEvent(self, event, args):191 """Private method to queue events to run.192 Each event in queue is a tuple (event call, args to event call).193 """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 """276 if not isinstance(modifiers, list):277 raise TypeError('Please provide modifiers in list form')278 if not hasattr(self, 'keyboard'):279 self.keyboard = AXKeyboard.loadKeyboard()280 modFlags = 0281 # Press given modifiers282 for nextMod in modifiers:283 if nextMod not in self.keyboard:284 errStr = 'Key %s not found in keyboard layout'285 self._clearEventQueue()286 raise ValueError(errStr % self.keyboard[nextMod])287 modEvent = Quartz.CGEventCreateKeyboardEvent(288 Quartz.CGEventSourceCreate(0),289 self.keyboard[nextMod],290 pressed291 )292 if not pressed:293 # Clear the modflags:294 Quartz.CGEventSetFlags(modEvent, 0)295 if globally:296 self._queueEvent(Quartz.CGEventPost, (0, modEvent))297 else:298 self._queueEvent(Quartz.CGEventPostToPid, (self._getPid(), modEvent))299 # Add the modifier flags...

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run pyatom automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful