One method I use to keep the braces matched is I always type both if I type one. Then I put the code inside them.
I also use ctrl-t (format) in the IDE. It will give an error if the brackets don't match. The IDE will also highlight the matching bracket if you put your cursor on one.
Once you figure out the brackets look at the if statement around the switch. You should be able to eliminate that and have the switch handle any value of key.