Пример #1
0
 def _keyDescriptionForString(self, keyString: str) -> Dict:
     shift = (self._modifiers & 8)
     description = {
         'key': '',
         'keyCode': 0,
         'code': '',
         'text': '',
         'location': 0,
     }
     definition = keyDefinitions.get(keyString)
     if (not definition):
         raise PyppeteerError(''.join(
             ['Unknown key: ', '{}'.format(keyString)]))
     if ('key' in definition):
         description['key'] = definition['key']
     if (shift and definition.get('shiftKey')):
         description['key'] = definition['shiftKey']
     if ('keyCode' in definition):
         description['keyCode'] = definition['keyCode']
     if (shift and definition.get('shiftKeyCode')):
         description['keyCode'] = definition['shiftKeyCode']
     if ('code' in definition):
         description['code'] = definition['code']
     if ('location' in definition):
         description['location'] = definition['location']
     if (len(description['key']) == 1):
         description['text'] = description['key']
     if ('text' in definition):
         description['text'] = definition['text']
     if (shift and definition.get('shiftText')):
         description['text'] = definition['shiftText']
     if (self._modifiers & (~8)):
         description['text'] = ''
     return description
Пример #2
0
    def _keyDescriptionForString(self, keyString: str) -> Dict:  # noqa: C901
        shift = self._modifiers & 8
        description = {
            'key': '',
            'keyCode': 0,
            'code': '',
            'text': '',
            'location': 0,
        }

        definition: Dict = keyDefinitions.get(keyString)  # type: ignore
        if not definition:
            raise PyppeteerError(f'Unknown key: {keyString}')

        if 'key' in definition:
            description['key'] = definition['key']
        if shift and definition.get('shiftKey'):
            description['key'] = definition['shiftKey']

        if 'keyCode' in definition:
            description['keyCode'] = definition['keyCode']
        if shift and definition.get('shiftKeyCode'):
            description['keyCode'] = definition['shiftKeyCode']

        if 'code' in definition:
            description['code'] = definition['code']

        if 'location' in definition:
            description['location'] = definition['location']

        if len(description['key']) == 1:  # type: ignore
            description['text'] = description['key']

        if 'text' in definition:
            description['text'] = definition['text']
        if shift and definition.get('shiftText'):
            description['text'] = definition['shiftText']

        if self._modifiers & ~8:
            description['text'] = ''

        return description