Best Python code snippet using keyboard
_mouse_tests.py
Source:_mouse_tests.py
...37 mouse._os_mouse.append = self.events.append38 def tearDown(self):39 mouse.unhook_all()40 # Make sure there's no spill over between tests.41 self.wait_for_events_queue()42 def wait_for_events_queue(self):43 mouse._listener.queue.join()44 def flush_events(self):45 self.wait_for_events_queue()46 events = list(self.events)47 # Ugly, but requried to work in Python2. Python3 has list.clear48 del self.events[:]49 return events50 def press(self, button=LEFT):51 mouse._os_mouse.queue.put(ButtonEvent(DOWN, button, time.time()))52 self.wait_for_events_queue()53 def release(self, button=LEFT):54 mouse._os_mouse.queue.put(ButtonEvent(UP, button, time.time()))55 self.wait_for_events_queue()56 def double_click(self, button=LEFT):57 mouse._os_mouse.queue.put(ButtonEvent(DOUBLE, button, time.time()))58 self.wait_for_events_queue()59 def click(self, button=LEFT):60 self.press(button)61 self.release(button)62 def wheel(self, delta=1):63 mouse._os_mouse.queue.put(WheelEvent(delta, time.time()))64 self.wait_for_events_queue()65 def move(self, x=0, y=0):66 mouse._os_mouse.queue.put(MoveEvent(x, y, time.time()))67 self.wait_for_events_queue()68 def test_hook(self):69 events = []70 self.press()71 mouse.hook(events.append)72 self.press()73 mouse.unhook(events.append)74 self.press()75 self.assertEqual(len(events), 1)76 def test_is_pressed(self):77 self.assertFalse(mouse.is_pressed())78 self.press()79 self.assertTrue(mouse.is_pressed())80 self.release()81 self.press(X2)...
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!!