Best Python code snippet using pyatom_python
keypress_actions.py
Source:keypress_actions.py
...82 return_val.value=key83 return return_val84 # Key Undefined85 return return_val86 def get_keyval_id(self, input_str):87 index=088 key_vals=[]89 lastModifiers=None90 while index < len(input_str):91 token=''92 # Identified a Non Printing Key93 if input_str[index] == '<':94 index += 195 i=096 while input_str[index] != '>' and i < self._max_tok_size:97 token += input_str[index]98 index += 199 i += 1100 if input_str[index] != '>':101 # Premature end of string without an opening '<'102 return None103 index += 1104 else:105 token=input_str[index]106 index += 1107 key_val=self._get_key_value(token)108 # Deal with modifier and undefined keys.109 # Modifiers: if we got modifier in previous110 # step, extend the previous KeyCombo object instead111 # of creating a new one.112 if lastModifiers and key_val.value != self._undefined_key:113 last_item = key_vals.pop()114 if key_val.modifiers:115 lastModifiers = key_val116 last_item.modVal.extend(key_val.modVal)117 key_val = last_item118 else:119 last_item.value = key_val.value120 key_val = last_item121 lastModifiers=None122 elif key_val.modifiers:123 if not lastModifiers:124 lastModifiers=key_val125 else:126 last_item=key_vals.pop()127 last_item.modVal.extend(key_val.modVal)128 key_val=last_item129 elif key_val.value == self._undefined_key:130 # Invalid key131 return None132 key_vals.append(key_val)133 return key_vals134class KeyComboAction:135 """Used for sending keyboard events to the system."""136 def __init__(self, data):137 """138 @param data: data to type139 @type data: string140 """141 self._data=data142 # Create dummy window, it has code for creating and queuing events.143 # We will send events 'globally' to the system so dummy window will144 # not receive the event.145 self._dummy_window=NativeUIElement()146 _keyOp=KeyboardOp()147 self._keyvalId=_keyOp.get_keyval_id(data)148 if not self._keyvalId:149 raise LdtpServerException("Unsupported keys passed")150 self._doCombo()151 def _doCombo(self):152 for key_val in self._keyvalId:153 if key_val.modifiers:154 self._dummy_window.sendGlobalKeyWithModifiers(key_val.value,155 key_val.modVal)156 else:157 self._dummy_window.sendGlobalKey(key_val.value)158 time.sleep(0.01)159class KeyPressAction:160 def __init__(self, window, data):161 self._data=data162 self._window=window163 _keyOp=KeyboardOp()164 self._keyvalId=_keyOp.get_keyval_id(data)165 if not self._keyvalId:166 raise LdtpServerException("Unsupported keys passed")167 self._doPress()168 def _doPress(self):169 for key_val in self._keyvalId:170 if key_val.modifiers:171 self._window.pressModifiers(key_val.modVal)172 else:173 raise LdtpServerException("Unsupported modifiers")174 time.sleep(0.01)175class KeyReleaseAction:176 def __init__(self, window, data):177 self._data=data178 self._window=window179 _keyOp=KeyboardOp()180 self._keyvalId=_keyOp.get_keyval_id(data)181 if not self._keyvalId:182 raise LdtpServerException("Unsupported keys passed")183 self._doRelease()184 def _doRelease(self):185 for key_val in self._keyvalId:186 if key_val.modifiers:187 self._window.releaseModifiers(key_val.modVal)188 else:189 raise LdtpServerException("Unsupported modifiers")...
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!!