This code is modified from code I obtained through the following link: http://www.instructables.com/id/Arduino-LeonardoMicro-as-Game-ControllerJoystick/?
The instructable, the unmodified code, and the Joystick library were created by Matthew Heironimus. All credit for this code belongs to him. Without his work this code would not be possible.
This code requires that you have the arduino IDE version 1.6.6 or later. Tested with both 1.6.6 and 1.6.7 It WILL NOT work with earlier versions of the Arduino IDE.
This code also requires the "Joystick" library to work and it is NOT a library the Arduino IDE has by default. There is a link to it in the above instructable. Or through this link: https://github.com/MHeironimus/ArduinoJoystickLibrary