op <- options(digits.secs = 6) t=Sys.time() time = function(t) { txt=substr(t,12,30) le=nchar(txt) h=as.numeric(substr(txt,1,2)) m=as.numeric(substr(txt,4,5)) s=as.numeric(trimws(substr(txt,7,le))) return(c(h,m,s,h*3600+m*60+s)) } min.delay = 2 max.delay = 10 n.trials = 5 measure.my.reaction.times = function(n.trials= 5, min.delay= 2, # seconds max.delay=10, # seconds show.as.you.go=FALSE) { # show indidivual times reaction.times = rep(NA,n.trials) print(noquote("")) print(noquote("As soon as GO sign appears, press RETURN key")) print(noquote("")) for(trial in 1:n.trials) { t.0 = time(Sys.time()) t.start = t.0[4] + runif(1,min.delay,max.delay) #print(noquote("wait")) while( time(Sys.time())[4] < t.start ) { } t.message = time(Sys.time())[4] #print(Sys.time()) input <- readline(prompt=noquote("GO")) t.response = time(Sys.time())[4] #print(Sys.time()) reaction.times[trial] = round(1000*(t.response - t.message)) if(show.as.you.go) print(c(trial,reaction.times[trial])) } return(reaction.times) } # examples measure5times = measure.my.reaction.times() measure25times = measure.my.reaction.times(25) # note: JH hasn't figures out how to keep responses # that occur befire the GO notice from messing up the # remining timings. suggestions welcome # JH 2017.08.25