refactored keyboard and mouse support