当前位置: 首页>>代码示例>>Python>>正文


Python Key.space方法代码示例

本文整理汇总了Python中pynput.keyboard.Key.space方法的典型用法代码示例。如果您正苦于以下问题:Python Key.space方法的具体用法?Python Key.space怎么用?Python Key.space使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pynput.keyboard.Key的用法示例。


在下文中一共展示了Key.space方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: on_press

# 需要导入模块: from pynput.keyboard import Key [as 别名]
# 或者: from pynput.keyboard.Key import space [as 别名]
def on_press(self, key):
        value = None
        if key == Key.backspace:
            if len(self.data):
                del self.data[-1]

        elif key == Key.tab:
            value = '\t'

        elif key == Key.enter:
            value = '\n'

        elif key == Key.space:
            value = ' '

        elif len(str(key)) == 3:
            value = self.check_for_shift(key)

        else:
            self.lastkey = key

        if value != None:
            self.data.append(value) 
开发者ID:Pure-L0G1C,项目名称:Loki,代码行数:25,代码来源:keylogger.py

示例2: movement

# 需要导入模块: from pynput.keyboard import Key [as 别名]
# 或者: from pynput.keyboard.Key import space [as 别名]
def movement(self):
        # We stop accepting move inputs (but turning is ok) in the middle of a
        # jump -- the effect is momentum-like movement while in the air.
        keys = self.jumping_keys if self.player.is_jumping else self.keys
        if self.player_has_jumped:
            self.jumping_keys = self.keys.copy()
            self.player_has_jumped = False

        left = self.keys[Key.left] or self.keys[KeyCode(char='a')]
        right = self.keys[Key.right] or self.keys[KeyCode(char='d')]
        up = keys[Key.up] or keys[KeyCode(char='w')]
        down = keys[Key.down] or keys[KeyCode(char='s')]
        strafe_l = keys[KeyCode(char='q')]
        strafe_r = keys[KeyCode(char='e')]

        if left ^ right:
            self.player.turn(left)
        if up ^ down:
            self.player.move((up - down) * self.player.speed)
        if strafe_l ^ strafe_r:
            self.player.move((strafe_l - strafe_r) * self.player.speed, True)
        if self.keys[Key.space]:
            self.player_has_jumped = True
            self.player.is_jumping = True
            self.keys[Key.space] = False 
开发者ID:salt-die,项目名称:terminal_dungeon,代码行数:27,代码来源:controller.py

示例3: onKeyRelease

# 需要导入模块: from pynput.keyboard import Key [as 别名]
# 或者: from pynput.keyboard.Key import space [as 别名]
def onKeyRelease(key):
    global keys, charCount  #Access global variables
    if key == Key.esc:
        writeToFile()
        return False
    else:
        if key == Key.enter:    #Write keys to file
            writeToFile()
        elif key == Key.space:  #Write keys to file
            key = ' '
            writeToFile()
        keys.append(key)    #Store the Keys
        charCount += 1      #Count keys pressed 
开发者ID:Ajinkya-Sonawane,项目名称:Python,代码行数:15,代码来源:19_KeyLogger.py

示例4: writeToFile

# 需要导入模块: from pynput.keyboard import Key [as 别名]
# 或者: from pynput.keyboard.Key import space [as 别名]
def writeToFile():
    global keys, charCount
    with open('log.txt','a') as file:
        for key in keys:
            key = str(key).replace("'","")   #Replace ' with space
            if 'key'.upper() not in key.upper():
                file.write(key)
        file.write("\n")    #Insert new line
    keys,charCount = [],0 
开发者ID:Ajinkya-Sonawane,项目名称:Python,代码行数:11,代码来源:19_KeyLogger.py

示例5: key_to_action_default

# 需要导入模块: from pynput.keyboard import Key [as 别名]
# 或者: from pynput.keyboard.Key import space [as 别名]
def key_to_action_default(key):
    """
        MOVE_FORWARD
        MOVE_BACKWARD
        MOVE_RIGHT
        MOVE_LEFT
        SELECT_WEAPON1
        SELECT_WEAPON2
        SELECT_WEAPON3
        SELECT_WEAPON4
        SELECT_WEAPON5
        SELECT_WEAPON6
        SELECT_WEAPON7
        ATTACK
        SPEED
        TURN_LEFT_RIGHT_DELTA
    """
    from pynput.keyboard import Key

    # health gathering
    action_table = {
        Key.left: 0,
        Key.right: 1,
        Key.up: 2,
        Key.down: 3,
    }

    # action_table = {
    #     Key.up: 0,
    #     Key.down: 1,
    #     Key.alt: 6,
    #     Key.ctrl: 11,
    #     Key.shift: 12,
    #     Key.space: 13,
    #     Key.right: 'turn_right',
    #     Key.left: 'turn_left',
    # }

    return action_table.get(key, None) 
开发者ID:alex-petrenko,项目名称:sample-factory,代码行数:41,代码来源:doom_gym.py

示例6: _convert_actions

# 需要导入模块: from pynput.keyboard import Key [as 别名]
# 或者: from pynput.keyboard.Key import space [as 别名]
def _convert_actions(self, actions):
        """Convert actions from gym action space to the action space expected by Doom game."""

        if self.composite_action_space:
            # composite action space with multiple subspaces
            spaces = self.action_space.spaces
        else:
            # simple action space, e.g. Discrete. We still treat it like composite of length 1
            spaces = (self.action_space, )
            actions = (actions, )

        actions_flattened = []
        for i, action in enumerate(actions):
            if isinstance(spaces[i], Discretized):
                # discretized continuous action
                # check discretized first because it's a subclass of gym.spaces.Discrete
                # the order of if clauses here matters! DON'T CHANGE THE ORDER OF IFS!

                continuous_action = spaces[i].to_continuous(action)
                actions_flattened.append(continuous_action)
            elif isinstance(spaces[i], gym.spaces.Discrete):
                # standard discrete action
                num_non_idle_actions = spaces[i].n - 1
                action_one_hot = np.zeros(num_non_idle_actions, dtype=np.uint8)
                if action > 0:
                    action_one_hot[action - 1] = 1  # 0th action in each subspace is a no-op

                actions_flattened.extend(action_one_hot)
            elif isinstance(spaces[i], gym.spaces.Box):
                # continuous action
                actions_flattened.extend(list(action * self.delta_actions_scaling_factor))
            else:
                raise NotImplementedError(f'Action subspace type {type(spaces[i])} is not supported!')

        return actions_flattened 
开发者ID:alex-petrenko,项目名称:sample-factory,代码行数:37,代码来源:doom_gym.py


注:本文中的pynput.keyboard.Key.space方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。