0

I am writing a code where it is automated after the user interacts with the site, I currently have it on a 30 second timer (sleep(30)) where the user can interact for 30 seconds and the the automated code happens. Is there a quick ruby gem that I can use to delay / sleep the code until say the "r" key is pressed by the user.

Mario Galic
  • 47,285
  • 6
  • 56
  • 98

1 Answers1

0

The gets method will halt execution until the user enters input:

loop do
 if gets.chomp == "r"
    # ... do what you need when the key is pressed
    break
  end
end

The user will have to press return to submit their input though. If you don't want to require the return button to be pressed, you can use something like STDIN.getch as described here: https://stackoverflow.com/a/34594382/2981429

max pleaner
  • 26,189
  • 9
  • 66
  • 118
  • Im more wondering if there is a way to unpause a program while on a webpage with a hotkey instead of using a gets with a terminal. – mozartsghost Jul 21 '20 at 22:21