Implement events API and improve joystick scanning API