Optimize key event

Optimize key-event's key-press handler and optimize String::startsWith, String::endsWith and String::trimFirstStr.

The optimization of key-event's key-press handler depends on the key mappings to not be regexes but to be just keys. I think this works fine but please do double check that everything works fine and tell me if you find some issues.