That is almost valid, but keys is an attribute of the keyboard component rather than being a stand-alone variable, so you need to add its name, like this:

your_keyboard_component_name.keys[-1] == 'return'

However, all that will do is stop the keyboard component from running: it won’t end the trial. So you should instead put that code in a code component rather than in the keyboard component, as that way you can add a line or two. e.g. put something like this in the Each frame tab of a code component so that it runs on every screen refresh: