Added a function to convert key name to key code in events.