Improve key code recognition