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.
Asked
Active
Viewed 483 times
0
-
This question seems to misunderstand on a fundamental level how web apps work. – anothermh Jul 21 '20 at 22:56
1 Answers
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