【发布时间】:2017-01-10 16:05:13
【问题描述】:
我正在为脚本创建设置。我需要设置以包含脚本本身的键盘快捷键。基本上,一个简单的方法是使用相当于 Ubuntu 的 bind 命令的 Windows 7。如何在 Python 中做到这一点?
我尝试过的:
我在某处读到创建vcst 文件将允许我进行键绑定,所以我尝试了这个:
def run_setup(self):
with open(self.file_name, 'a+') as vsct:
vsct.write("""<KeyBindings>
<KeyBinding guid="esc_tool" id="c:\users\{}\desktop\esc_tool\main.py"
key1="8" mod1="CONTROL" mod2="ALT"/>
</KeyBindings>
""".format(getpass.getuser()))
那没用。
我怎样才能成功地做到这一点?
编辑
上面的内容似乎有点令人困惑,所以我想做的是从名为setup.py 的脚本内部为名为@987654324@ 的脚本创建一个键盘快捷键。所以:
python setup.py 使用 CNTRL-ALT-8 键创建一个键盘快捷键,该快捷键指向名为 main.py 的脚本。因此,当用户按下 CNTRL-ALT-8 时,它会在 Python 解释器中运行 main.py。
【问题讨论】:
-
您能否将其编辑为更具描述性,以便我想出一个对您有帮助的答案。
-
@Harrison 刚刚做了
标签: python windows-7 keyboard-shortcuts