Create joystick object


joy = vrjoystick(id)
joy = vrjoystick(id,'forcefeedback')


joy = vrjoystick(id) creates a joystick object capable of interfacing with a joystick device. The id parameter is a one-based joystick ID. The joystick ID is the system ID assigned to the given joystick device. You can find the properties of the joystick that is connected to the system in the Game Controllers section of the system Control Panel.

joy = vrjoystick(id,'forcefeedback') enables force feedback if the joystick supports this capability.


axis a = axis(joy, n)reads the status of joystick with axis number n. Axis status is returned in the range of -1 to 1. The n parameter may be a vector to return multiple buttons.
buttonb = button(joy, n) reads the status of joystick button number n. Button status is returned as logical 0 if not pressed and logical 1 if pressed. The n parameter may be a vector to return multiple buttons.
capsc = caps(joy) returns joystick capabilities, such as the number of axes, buttons, POVs, and force-feedback axes. The return value is a structure with fields named Axes, Buttons, POVs, and Forces.
closeclose(joy) closes and invalidates the joystick object. The object cannot be used once it is closed.
forceforce(joy, n, f) applies force feedback to joystick axis n. The n parameter can be a vector to affect multiple axes. f values should be in range of -1 to 1, and the number of elements in f should either match the number of elements of n, or f can be a scalar to be applied to all the axes specified by n.
povp = pov(joy, n) reads the status of joystick POV (point of view) of control number n. pov is usually returned in degrees, with -1 meaning "not selected." n can be a vector to return multiple POVs.
read[axes, buttons, povs] = read(joy) reads the status of axes, buttons, and POVs of the specified joystick. [axes, buttons, povs] = read(joy, forces) applies feedback forces, in addition, to a force-feedback joystick.

where joy is the handle to the joystick object.

Introduced in R2007b

Was this topic helpful?