Improve key-event generation