简体   繁体   English

我可以通过键盘快捷键运行 python 脚本吗?

[英]Can I run a python script from a keyboard shortcut?

I want to be able to run a python script like a keyboard macro, just by pressing a certain combination of buttons.我希望能够像键盘宏一样运行 python 脚本,只需按下某个按钮组合即可。 Is it possible, if yes, how?有没有可能,如果有,怎么做?

Depending on your operating system there will be different ways to run scripts via hot keys.根据您的操作系统,将有不同的方式通过热键运行脚本。 If you create and auto run a script with "key listeners" you can use that to execute other scripts.如果您使用“关键侦听器”创建并自动运行脚本,您可以使用它来执行其他脚本。 There are a few libraries you could use and I've attached a couple of them below.您可以使用一些库,我在下面附上了其中的几个。

PyAutoGUI PyAutoGUI

Pynput皮普普特

Yes, if you're on a Mac, you can create a 'quick action' in Automate using an apple script to tell Terminal to do something like 'tell application "Terminal" to do script "python myscript.py"'.是的,如果您使用的是 Mac,您可以在 Automate 中创建一个“快速操作”,使用苹果脚本告诉终端执行类似“告诉应用程序“终端”执行脚本“python myscript.py”之类的操作。 Then, you can go into your keyboard shortcut preferences and add a hotkey to the action.然后,您可以将 go 放入您的键盘快捷键首选项中,并为操作添加热键。

you click f5 if you have windows如果您有 windows,请单击 f5

Try Ctrl + F5 .尝试Ctrl + F5 It worked for me.它对我有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM