Keyboard input and time synchronisation

Hi!

I am writing a simple script that captures the keyboard input and tries to see if
the keys were pressed with a certain pattern. When a key is pressed a sound is played if the main character has enough “money”.
I have background music (say 90bpm) and I would like to check with the script if a certain sequence of keys is played and record their time.

I am stuck with the following code:

from bge import events 
from bge import logic

cont = logic.getCurrentController()
own = cont.owner
objList = logic.getCurrentScene().objects


#:::::::::::::::::::::::::::::::::::::::::#
#		      S E N S O R S               #
#:::::::::::::::::::::::::::::::::::::::::#

h=cont.sensors["h_key"]
j=cont.sensors["j_key"]
k=cont.sensors["k_key"]
l=cont.sensors["l_key"]
money_test = cont.sensors["money_test"]


#:::::::::::::::::::::::::::::::::::::::::#
#	        A C T U A T O R S             #
#:::::::::::::::::::::::::::::::::::::::::#

mush = cont.actuators["musich"]
musj = cont.actuators["musicj"]
musk = cont.actuators["musick"]
musl = cont.actuators["musicl"]


#:::::::::::::::::::::::::::::::::::::::::#

print("Music"+str(own['money_count']))


if h.positive and own['money_count']>0:
    own['money_count'] = own['money_count'] - 1
    print("h")
    cont.activate(mush)
    
if j.positive and own['money_count']>0:
    own['money_count'] = own['money_count'] - 1
    print("j")
    cont.activate(musj)
    
if k.positive and own['money_count']>0:
    own['money_count'] = own['money_count'] - 1
    print("k")
    cont.activate(musk)
    
    
if l.positive and own['money_count']>0:
    own['money_count'] = own['money_count'] - 1
    print("l")
    cont.activate(musl)

How can I check the sequence of keys? Storing the previous one in an array or something like this? How to capture the time when the key was pressed?

Thank you very much in advance!