+ let delay =
+ match !end_time with
+ | None ->
+ (* No --end-time option, so use the current delay. *)
+ !delay
+ | Some end_time ->
+ let (_, time, _, _, _, _, _, _) = state in
+ let delay_secs = float !delay /. 1000. in
+ if end_time <= time +. delay_secs then (
+ quit := true;
+ let delay = int_of_float (1000. *. (end_time -. time)) in
+ if delay >= 0 then delay else 0
+ ) else
+ !delay in
+ (*eprintf "adjusted delay = %d\n%!" delay;*)
+
+ (* Get next key. This does the sleep. *)
+ if not batch_mode && not script_mode then
+ get_key_press setup delay
+ else (
+ (* Batch mode or script mode. We didn't call get_key_press, so
+ * we didn't sleep. Sleep now, unless we are about to quit.
+ *)
+ if not !quit || !end_time <> None then
+ millisleep delay
+ )