4

I am trying to hold down the 'shift' key and press the 'down' key using the pyautogui module. But the pyautogui.keyDown() does not function with shift key.

The py.keyDown('shift') does not seem to work. Only the py.press('down') is working without holding down the shift key.

pyautogui.keyDown('shift')
pyautogui.press('down')
pyautogui.press('down')
pyautogui.keyUp('shift')

The thing i would like to do is- hold down the shift key and use the down arrow keys on the key board to move down selecting all items below with the down arrow.

Cool coder
  • 41
  • 1
  • 3
  • Look at this thread: https://stackoverflow.com/questions/53489809/pyautogui-doesnt-let-me-select-text . Disabling the numpad worked for me. – y4cine Jul 12 '19 at 14:38

3 Answers3

6

#You can try this #So, you have to make left and right shifts down at the same time to activate this feature which is wired.

pyautogui.keyDown('shiftleft')
pyautogui.keyDown('shiftright')
pyautogui.hotkey('right','right','ctrl','up')
pyautogui.keyUp('shiftleft')
pyautogui.keyUp('shiftright')

#credits:Tian Chu #https://stackoverflow.com/users/13967128/tian-chu

Frans
  • 61
  • 1
  • 2
1

Previous answer is good. I was able to successfully highlight a whole Excel column using:

pyautogui.hotkey('ctrl','shiftright','shiftleft','down')

I tried using both shiftright and shiftleft on their own and it wouldn't work unless they were both used together.

ppwater
  • 2,315
  • 4
  • 15
  • 29
  • 1
    Disabling the numlock key helped me fix this..So basically to foolproof my program I had to check if the numlock key was ON or OFF. – Cool coder Dec 24 '20 at 05:22
1

Thanks, I lost almost 1 hour to find this answer cause on the documentation this is not specified, for me worked example:

py.keyDown('shiftleft')

py.keyDown('shiftright')

py.press('down', presses=253)

py.keyUp('shiftleft')

py.keyUp('shiftright')

Again, Thanks.