'PYAUTOGUI.HOTKEY
I know that the most usefull tool to create and manipulate workbook/paste are Pandas or Openpyxl.
My problem is with TOTVS: I find a table in its program and I need to copy to a DB.
I was trying going through an entire column by just using pyautogui.hotkey('ctrl','shift','down')
. But, instead of selecting the entire column, it goes just to the end. With none selection.
Solution 1:[1]
I noticed similar issue on my side.
To me it looks like PyAutoGUI possibly has some issues with simulating pressing more than two non-alphanumeric buttons as hotkeys.
Let me clarify my experience:
My setup:
- Windows 10
- VS Code (latest)
- Chrome (latest)
- Python (3.10)
- PyAutoGUI (latest)
I tried to automate Chrome cache/cookies clearing using hotkeys CTRL + SHIFT + DEL combination:
import pyautogui, time
pyautogui.click(256,1056) # Chrome icon click
time.sleep(2)
pyautogui.click(952,606) # click on Chrome empty page
pyautogui.hotkey('ctrl', 'shift', 'delete')
Result: Visually pyautogui.hotkey
command doesn't seem to be executed, Chrome cache/cookies clearing window isn't opened.
I had several theories on why it doesn't work properly (turned out they all are irrelevant):
- Key naming is wrong -> tried all corresponding key names from this official manual.
pyautogui.PAUSE
setting affects hotkeys action -> removed it from script.- PyAutoGUI isn't focused on Chrome, therefore hotkeys are sent to wrong app -> added extra click in a middle of empty Chrome page to make sure it is focused.
- Windows confuses this hotkey combination with different one before everything is pressed -> changed all corresponding Windows hotkeys combinations.
- This is just
pyautogui.hotkey
issue -> tried to workaround it usingpyautogui.hold
andpyautogui.keyDown
As a result for last one I've seen part of hotkeys combination working (CTRL + SHIFT was pressed).
For others result was the same as for initial script (cache/cookies clearing window isn't opened).
I finally tried to just open Windows task manager by CTRL + ALT + DEL combination. It doesn't work as well for me. Behavior is the same as one for Chrome script.
At the same time key combinations including alphanumeric keys inside Chrome (for example, CTRL + SHIFT + N) and outside it (CTRL + A) are working flawlessly, just as expected.
UPD: I just found another approach, and I think it gives some clues.
I used W3C online key event viewer to see keyboard input logs.
Here are results:
case 1:
pyautogui.hotkey('ctrlleft', 'shiftleft', 'altleft')
keyboard input log:
case 2:
pyautogui.hotkey('ctrlleft', 'shiftleft', 'delete')
keyboard input log:
May anyone explain what happens in case 2 and why?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 |