How do I press 2 keys at a time using pyautogui?

huangapple go评论88阅读模式
英文:

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"])

huangapple
  • 本文由 发表于 2023年5月11日 09:04:48
  • 转载请务必保留本文链接:https://go.coder-hub.com/76223487.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定