1

I'm trying to get text from the screen automatically using pyautogui, with this code:

pyautogui.keyDown('shift')
time.sleep(0.1)
pyautogui.press('esc')
pyautogui.press(['down','down','down','down'])
pyautogui.keyUp('shift')
pyautogui.hotkey('ctrl','c')

but the command keyDown('shift') doesn't work. Could someone help me with this error?

pppery
  • 3,731
  • 22
  • 33
  • 46
user3815068
  • 191
  • 1
  • 1
  • 10
  • Are you on Windows? Is this ( https://github.com/asweigart/pyautogui/issues/15 ) helpful? – Claudio Feb 06 '19 at 22:02
  • 3
    I fix this error! For some reason the shift does not work with the casplock or numlock activated, I made a command to find out if any of the two is active, if yes disable! – user3815068 Feb 08 '19 at 18:02
  • @user3815068, how did you get status of capslock and/or numlock? This doesn't seem to be available from pyautogui – bfris Oct 26 '21 at 18:03

1 Answers1

0

Pyautogui should let you use the hotkeys here, and you could probably tidy things up with a loop:

for i in range(0, times_to_run):
    pyautogui.hotkey('shift', 'down')

Then you don't have to worry about using keyUp or time.sleep().

aschultz
  • 1,658
  • 3
  • 20
  • 30
  • for i in range(4): pyautogui.hotkey('shift', 'down') – Alwyn Miranda Jun 10 '20 at 15:45
  • @AlwynMiranda are you sure you're not mixing up down with page-down? When I retried my code to see what might be wrong, I confused the two myself. But if you, say, highlight the "should" in my response and run the code, you will see a bit more text highlighted with each iteration, as should happen with shift-down. I am using Python 3.7 on Windows 7. – aschultz Jun 10 '20 at 20:52