improve event handle for keyboard and mouse