Added optional keypress delay to tap_key and adjusted the sleep call in type_string to occur at the end of the loop
More work, all untested