2

I want to record some typing on a screen video using emacs and I'm wondering if there is something available in emacs to mimic human typing. I imagine I feed it a line(region) of text and it is displayed in the buffer, character by character which a human can follow. A bit faster and without backspace correction than my live typing, but still a lot slower than just playing back an recorded macro?

Drew
  • 75,699
  • 9
  • 109
  • 225
dr jerry
  • 321
  • 1
  • 7

1 Answers1

4

You probably want to use the function sit-for:

(sit-for SECONDS &optional NODISP)

Redisplay, then wait for SECONDS seconds. Stop when input is available. SECONDS may be a floating-point value.

So you could do something like that:

(defun insert-like-human (text &optional delay)
  (let ((d (or delay 0.1)))
    (mapc (lambda (c) (sit-for d) (insert c)) text)))

You can call it with M-: (insert-like-human "my text") or M-: (insert-like-human "my slower text" 0.2).

As mentionned by @zck, you could also use random delay to make it look more natural, eg:

(defun insert-like-human (text &optional delay)
  (let ((d (or delay 0.2)))
    (mapc (lambda (c) (sit-for (cl-random d)) (insert c)) text)))
JeanPierre
  • 7,323
  • 1
  • 18
  • 37
  • One could even use `cl-random` to make the time delay between two characters differ, depending how predictable you want it to look. For example, `(+ 0.05 (cl-random 0.2))` results in a random number between 0.05 and 0.25 seconds. – zck Sep 09 '19 at 21:30
  • perfect! Thanks, now I only need some typing sound :-) – dr jerry Sep 10 '19 at 13:00
  • M-x play-sound-file (seriously!) – JeanPierre Sep 10 '19 at 13:29