Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

keyDown function not working with shift key

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.

like image 409
Cool coder Avatar asked Nov 17 '25 02:11

Cool coder


2 Answers

#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

like image 192
Frans Avatar answered Nov 18 '25 21:11

Frans


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.

like image 39
Liam McKenna Avatar answered Nov 18 '25 21:11

Liam McKenna



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!