I’m trying to write a program that asks the user to enter a password and then measures the timing between each keystroke after they have entered it. Is this possible?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
In so far as you can ask Ruby to give you raw i/o and then get the time stamp after each read returns, yes you can. If you really need very high precision though, ruby itself will add some microseconds of latency.
Presuming that is not a problem, do something like getting a raw file descriptor for /dev/tty, use ioctls to set it for raw mode, and use the read method to get each character as it is entered. This is, of course, messy, but what you are asking for is hard to do in a non-messy manner. (It is also not portable between OSes, but it is portable across versions of Unix. You will not be able to do precisely the same thing on Windows, you’ll need different code for that.)