Return the dictionary of keyboard keys to actions.
516669
def get_keys_to_action(self):
        """"""
        # keyboard keys in an array ordered by their byte order in the bitmap
        # i.e. right = 7, left = 6, ..., B = 1, A = 0
        buttons = np.array([
            ord('d'),  # right
            ord('a'),  # left
            ord('s'),  # down
            ord('w'),  # up
            ord('\r'), # start
            ord(' '),  # select
            ord('p'),  # B
            ord('o'),  # A
        ])
        # the dictionary of key presses to controller codes
        keys_to_action = {}
        # the combination map of values for the controller
        values = 8 * [[0, 1]]
        # iterate over all the combinations
        for combination in itertools.product(*values):
            # unpack the tuple of bits into an integer
            byte = int(''.join(map(str, combination)), 2)
            # unwrap the pressed buttons based on the bitmap
            pressed = buttons[list(map(bool, combination))]
            # assign the pressed buttons to the output byte
            keys_to_action[tuple(sorted(pressed))] = byte

        return keys_to_action
448643
def describe_keypairs(self, *keypair_names):
        """"""
        keypairs = {}
        for index, keypair_name in enumerate(keypair_names):
            keypairs["KeyName.%d" % (index + 1)] = keypair_name
        query = self.query_factory(
            action="DescribeKeyPairs", creds=self.creds,
            endpoint=self.endpoint, other_params=keypairs)
        d = query.submit()
        return d.addCallback(self.parser.describe_keypairs)
316984
def plain_keys(self):
        """"""
        return dict([(a, e) for a, e in self.entries.items()
                     if isinstance(e, BksKeyEntry)])
1267922
def action_get(key=None):
    """"""
    cmd = ['action-get']
    if key is not None:
        cmd.append(key)
    cmd.append('--format=json')
    action_data = json.loads(subprocess.check_output(cmd).decode('UTF-8'))
    return action_data
867813
def to_dict(self):
        """"""
        mydict = {'id': self.id, 'name': self.name,
                  'description': self.description,
                  'kbtype': self.kbtype}
        if self.kbtype == 'd':
            mydict.update((self.kbdefs.to_dict() if self.kbdefs else {}) or {})

        return mydict
790918
def get_selected_keys(self, selection):
        """"""
        return [k for k, b in self._lookup.items() if b & selection]
1094319
def private_keys(self):
        """"""
        return dict([(a, e) for a, e in self.entries.items()
                     if isinstance(e, PrivateKeyEntry)])
950057
def stats_keyboard(events, table):
    """"""
    if len(events) < 2: return [], []
    deltas, prev_dt = [], None
    sessions, session = [], None
    UNBROKEN_DELTA = datetime.timedelta(seconds=conf.KeyboardSessionMaxDelta)
    blank = collections.defaultdict(lambda: collections.defaultdict(int))
    collated = [blank.copy()] # [{dt, keys: {key: count}}]
    for e in events:
        if prev_dt:
            if (prev_dt.second != e["dt"].second
            or prev_dt.minute != e["dt"].minute or prev_dt.hour != e["dt"].hour):
                collated.append(blank.copy())
            delta = e["dt"] - prev_dt
            deltas.append(delta)
            if delta > UNBROKEN_DELTA:
                session = None
            else:
                if not session:
                    session = []
                    sessions.append(session)
                session.append(delta)
        collated[-1]["dt"] = e["dt"]
        collated[-1]["keys"][e["realkey"]] += 1
        prev_dt = e["dt"]
    longest_session = max(sessions + [[datetime.timedelta()]], key=lambda x: sum(x, datetime.timedelta()))
    stats = [
        ("Average interval between combos",
         sum(deltas, datetime.timedelta()) / len(deltas)),
    ] if "combos" == table else [
        ("Keys per hour",
         int(3600 * len(events) / timedelta_seconds(events[-1]["dt"] - events[0]["dt"]))),
        ("Average interval between keys",
         sum(deltas, datetime.timedelta()) / len(deltas)),
        ("Typing sessions (key interval < %ss)" % UNBROKEN_DELTA.seconds,
         len(sessions)),
        ("Average keys in session",
         sum(len(x) + 1 for x in sessions) / len(sessions)),
        ("Average session duration", sum((sum(x, datetime.timedelta())
         for x in sessions), datetime.timedelta()) / len(sessions)),
        ("Longest session duration",
         sum(longest_session, datetime.timedelta())),
        ("Keys in longest session",
         len(longest_session) + 1),
        ("Most keys in session",
         max(len(x) + 1 for x in sessions)),
    ]
    return stats, collated
404745
def GetInput(self):
        ""
        actions = 1
        # if both up and down
        if self.up and self.down:
            actions = 2

        inputs = (INPUT * actions)()

        vk, scan, flags = self._get_key_info()

        for inp in inputs:
            inp.type = INPUT_KEYBOARD

            inp._.ki.wVk = vk
            inp._.ki.wScan = scan
            inp._.ki.dwFlags |= flags

        # if we are releasing - then let it up
        if self.up:
            inputs[-1]._.ki.dwFlags |= KEYEVENTF_KEYUP

        return inputs
104395
def find_actions(namespace, action_prefix):
    """"""
    actions = {}
    for key, value in iteritems(namespace):
        if key.startswith(action_prefix):
            actions[key[len(action_prefix):]] = analyse_action(value)
    return actions
480694
def keys(self, start=None, stop=None):
        """"""
        return (item[0] for item in self.items(start, stop))
767579
def keys_to_typing(value):
    """"""
    typing = []
    for val in value:
        if isinstance(val, Keys):
            typing.append(val)
        elif isinstance(val, int):
            val = str(val)
            for i in range(len(val)):
                typing.append(val[i])
        else:
            for i in range(len(val)):
                typing.append(val[i])
    return typing
1358472
async def ListKeys(self, entities, mode):
        '''
        
        '''
        # map input types to rpc msg
        _params = dict()
        msg = dict(type='KeyManager',
                   request='ListKeys',
                   version=1,
                   params=_params)
        _params['entities'] = entities
        _params['mode'] = mode
        reply = await self.rpc(msg)
        return reply
875606
def all_keys(self):
        '''
        
        '''
        keys = self.list_keys()
        keys.update(self.local_keys())
        return keys
1299704
def get_keys(self):
        
        return [(self.first_key + i) for i in range(0, len(self.targets))]
1086478
def shortcuts(self):
        """"""
        return {name: action.shortcut
                for name, action in self._actions_dict.items()}
396519
def keys(self):
        """"""
        keys = []
        for app_name, __ in self.items():
            keys.append(app_name)
        return keys