Admittedly, it already exists – http://code.google.com/p/prok-screen/ but its awkward way of doing things (exposing functions using ActiveX server) was a bit of overkill for our needs. Hence, this stripped down, pure MEX version. Enjoy.
Usage: [position, buttons] = mat_joy(joystick_id), where:
joystick_id – joystick identifier (0-15),
position – list of joystick position in X, Y and Z axis,
buttons – list of 16 joystick button states (missing buttons are always zeros)