Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pyautogui hotkey command not working in Pycharm

On Pycharm in Mac, I am using Pyautogui to perform simple operation of Select all with Command+A using hotkey() function.

The code works in scenario:

import pyautogui

pyautogui.press("b")

pyautogui.hotkey("command", "a")

# Cursor here: b

with all text selected. But does not work in the scenario:

import pyautogui

pyautogui.hotkey("command", "a")

# Cursor here: a

where it simply prints the second key in the hotkey which is a

Same thing happens when I do it in Atom. Can someone explain what’s wrong?

like image 714
ask_me Avatar asked Nov 21 '25 02:11

ask_me


1 Answers

In mac os, actually you need to press command key first before any key for the hotkey, so you need to add interval between them.

pyautogui.hotkey("command", "a", interval=0.25 )
pyautogui.hotkey("command", "r", interval=0.25 )  #to refresh page
pyautogui.hotkey("command", "t", interval=0.25 )  #new tab

etc.

like image 135
Brifeb Avatar answered Nov 22 '25 15:11

Brifeb