Negative keyboard reaction times

I’m a complete beginner to Psychopy and this is the first experiment I’m coding in it. So, the experiment I’m doing is to ask the user to press a key whenever the letter ‘s’ appears on the screen. Then, I am recording the reaction time of the key press. But I am getting negative reaction times. Can someone explain to me what is the problem in my code?

from psychopy import visual, core, clock
from psychopy.hardware import keyboard
import random, string

num = 30
reac_times = []
count = 0
incorr_press = 0
rand_str = list(''.join(random.choices(string.ascii_lowercase, k = num)))
for c in rand_str:
     if c == 's' or c =='m':
         rand_str.remove(c)
targ_str = ['ms']
for i in range(0,10):
     index = random.randint(0,len(rand_str))
     rand_str = rand_str[:index] + targ_str + rand_str[index:]
new_str = ''.join([str(elem) for elem in rand_str])

win = visual.Window([400,400])
instr = visual.TextStim(win, text = "Press any key whenever letter 's' appears on screen")
instr.pos = (0,0.8)
instr.autoDraw = True
win.flip()

kb = keyboard.Keyboard()
clock = core.Clock()

for i in range(0, len(new_str)):
     msg = visual.TextStim(win, text = new_str[i])
     msg.draw() 
     win.flip()
     core.wait(1.5)
     kb.clock.reset()
     keys = kb.getKeys()
     if keys:
         if  new_str[i] == 's':
             count = count + 1
             reac_times.append(keys[0].rt)
             print(reac_times)
         else:
             incorr_press = incorr_press+1
     
    

print(reac_times)
print(count)

win.close()
core.quit()

I think you have to move the kb.clock.reset() call before the core.wait(1.5) function. The timestamp is relative to the last reset, so if anyone pressed a key during the wait period that will come out as a negative reaction time.

Hey, Thanks! It worked.