英文:
How do I press 2 keys at a time using pyautogui?
问题
我想在我的 Mac 上按下 Control + 左箭头键来切换屏幕。
这是我尝试过的代码:
import pyautogui
pyautogui.press(["ctrl", "left"])
但它不起作用。
英文:
I want to press control + left arrow on my mac to swipe my screen.
This is what I tried:
import pyautogui
pyautogui.press(["ctrl" ,"left"])
it does not work.
答案1
得分: 0
你可以使用pyautogui.hotkey()来实现这个。在你的示例中,你可以运行:
pyautogui.hotkey('ctrl', 'left')
英文:
For this you can use pyautogui.hotkey(). In your example you would run :
pyautogui.hotkey('ctrl', 'left')
答案2
得分: 0
The code seems correct. the problem might be because you are running the code in your IDE, and you might have clicked on the text or something like that (it happened to me before). Try adding a for loop.
import pyautogui
for i in range(5):
pyautogui.press(["ctrl", "left"])
If it works then consider making a simple prompt with a button to do it.
import pyautogui
while True:
result = pyautogui.confirm('click "swipe" to swipe', buttons=["swipe", "no"])
if result == "swipe":
pyautogui.press(["ctrl", "left"])
英文:
the code seems correct. the problem might be because you are running the code in your IDE, and you might have clicked on the text or something like that (it happended to me before). Try adding a for loop.
import pyautogui
for i in range(5):
pyautogui.press(["ctrl" ,"left"])
if it works then consider making a simple prompt with a button to do it.
import pyautogui
while True:
result = pyautogui.confirm('click "swipe" to swipe', buttons = ["swipe", "no"])
if result == "swipe":
pyautogui.press(["ctrl" ,"left"])
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论