In the competition task, the reaction times of two participants in each trail are compared

OS: Win 10
PsychoPy version : 3-3.1.5 (Builder)

Hello, I wanted to design an experiment like this:
In a competing task, two participants were asked to press the “Z” and “M” keys as quickly as possible when a stimulus signal was presented.
If the reaction time difference is within 50ms, the two people are tied.
If the reaction time difference is greater than 50ms, the faster player wins.

My question is:
How do I compare the reaction times of the two keys in each Trail?
As far as I know, .rt is a list. How to compare the size of two lists?

@Wenrui , you can use the following in the “End Routine” tab, where your keyboard component is called “key_resp”, and the keyboard is set to record “all keys”:

def getRT(kb, player):
    # Get first response or return false for no resp
    idx = 0
    for key in kb.keys:
        if key == player:
            return kb.rt[idx]
        idx += 1
    return False
    
def getDiff(p1, p2):
    # draw
    if abs(p1 - p2) < .050:
        return 0
    # p1 win
    elif (p2 - p1) > .050:
        return 1
    # p2 win
    elif (p1 - p2) > .050:
        return 2

# Get first response from each player
p1RT = getRT(key_resp, 'z')
p2RT = getRT(key_resp, 'm')
# If both responded
if p1RT and p2RT:
    result = getDiff(p1RT, p2RT)
    thisExp.addData("result", result)
    thisExp.addData("p1RT", p1RT)
    thisExp.addData("p2RT", p2RT)
# no responses from p1 or p2
elif not p1RT and not p2RT:
    thisExp.addData("result", 0)
# p2 no response - p1 wins
elif p1RT:
    thisExp.addData("result", 1)
    thisExp.addData("p1RT", p1RT)
# p1 no response - p2 wins
elif p2RT:
    thisExp.addData("result", 2)
    thisExp.addData("p2RT", p2RT)

You can put those functions in the Begin Experiment tab.

Thank you very much for your help! Your code inspired me a lot!
Before receiving your help, I took the following code, and basically solved my problem.

#Begin Experiment

#According to different game results, participants were presented with different responses and result pictures.
respone1 = 0
result1 = 0

#Each Frame 

#When both players have pressed the key, the game response and result are presented.
if len(select_1.keys) ==1 and len(select_2.keys) ==1:
     continueRoutine = False

#End Routine

#Comparing the reaction time of players in the game, three different responses and results are presented.
if select_1.rt < (select_2.rt - 0.05):
    respone1='dolphin\\\\stimulus\\\\feedback2.PNG'
    result1='dolphin\\\\stimulus\\\\result3.PNG'
    
elif select_1.rt > (select_2.rt + 0.05):
    respone1='dolphin\\\\stimulus\\\\feedback3.PNG'
    result1='dolphin\\\\stimulus\\\\result4.PNG'
    
elif select_1.rt > (select_2.rt - 0.05) and select_1.rt < (select_2.rt + 0.05):
    respone1='dolphin\\\\stimulus\\\\feedback1.PNG'
    result1='dolphin\\\\stimulus\\\\resul
1 Like