How can I detect if a key is pressed?

You can use the command keys pressed, from the Jon’s Commands scripting addition.