I am trying to use PyAutoGUI (Python 3.7 64-bit) to copy a column of cells in Excel from one sheet to another.
The code is:
import pyautogui as gui
gui.PAUSE = 1
gui.FAILSAFE = True
gui.keyDown('shift')
gui.typewrite(['down']*67)
gui.keyUp('shift')
gui.keyDown('ctrl')
gui.press('c')
gui.keyUp('ctrl')
which should hold down shift, click the down arrow 67 times to select the cells I want, then release shift. Following this, the text will be copied to the clipboard.
When run (with the top cell pre-selected), the delay of each step is noticeable, but it is as if shift is not held down. The selected cell moves to the bottom, but the previous cells are not selected. At the bottom, the last cell is copied.
It seems as though 'ctrl' is working, but 'shift' is not. If I stop before running keyUp on shift, when the program ends, my computer is act as if shift is being help down until I press the key again. I have also tried using 'shiftright' in case that was the issue but it made no difference. There are a number of PyAutoGUI functions run before these, but none have to do with the state of these keys.
I have also been looking at alternatives to select these cells without using shift but haven't been able to find anything.
Does anyone have suggestions on this?