AttributeError: 'BuilderKeyResponse' object has no attribute 'tt'

The error is very likely due to you assigning conditionally to PMtask.tt. i.e. that attribute doesn’t necessarily exist when it comes time to save the data. You need to debug the logic of your code.

You could test that by initially (i.e. unconditionally) assigning a default value like:

PMtask.tt = 'Not set'

If that value appears in your data, you know the source of the problem.

Quite possible, a part of your problem is that you are making multiple calls to event.getKeys() within a single screen refresh. This will get really unstable and unpredictable. A better strategy here is just to make one check per refresh and store it in a variable. Then check the value of that repeatedly in your code (taking into account time in the trial, etc), as required. Otherwise things get very unpredictable, depending on the exact time at which someone might press a key.

I’d advise using code components within Builder here rather than munging the code in Coder: it will impose some disciplines with regard to the event cycle.