changed keyboard and mouse events to use functions