Skip to main content

Joystick Class

NuGet: GHIElectronics.TinyCLR.Devices.UsbClient
Assembly: GHIElectronics.TinyCLR.Devices.UsbClient
Namespace: GHIElectronics.TinyCLR.Devices.UsbClient

This device emulates a joystick. You can set the x, y, and z axis values, the z axis rotation, the state of 32 buttons, and 8 hat swtich directions.

public class Joystick : RawDevice

Constructors​

Joystick(UsbClientController usbClientController)​

public Joystick(UsbClientController usbClientController) : this(usbClientController, new UsbClientSetting()

Creates a new joystick with default parameters.

Joystick(UsbClientController usbClientController, UsbClientSetting usbClientSetting)​

public Joystick(UsbClientController usbClientController, UsbClientSetting usbClientSetting) : base(usbClientController, usbClientSetting)

Creates a new joystick.

ParameterTypeDescription
usbClientControllerUsbClientControllerUsbClient controller.
usbClientSettingUsbClientSettingUsbClient setting

Properties​

X​

public int X { get; set; }

Sets the x axis position. It must be between –32,768 to +32,767.

Y​

public int Y { get; set; }

Sets the y axis position. It must be between –32,768 to +32,767.

Z​

public int Z { get; set; }

Sets the z axis position. It must be between –32,768 to +32,767.

ZRotation​

public int ZRotation { get; set; }

Sets the z rotation. It must be between –32,768 to +32,767.

HatSwitch​

public HatSwitchDirection HatSwitch { get; set; }

Sets the hat switch direction.

Methods​

SendRawData(int x, int y, int z, int zRotation, uint buttons, HatSwitchDirection hatSwitch)​

public void SendRawData(int x, int y, int z, int zRotation, uint buttons, HatSwitchDirection hatSwitch)

Sends the given raw data directly to the host..

ParameterTypeDescription
xintThe new x position from -32,768 to 32,767.
yintThe new y position from -32,768 to 32,767.
zintThe new z position from -32,768 to 32,767.
zRotationintThe new z rotation from -32,768 to 32,767.
buttonsuintSends the given uint as a bitfield where each 1 represents a button press for the button whose number is the bit number.
hatSwitchHatSwitchDirectionThe new direction of the hat switch.

IsButtonPressed(int index)​

public bool IsButtonPressed(int index)

Whether or not the given button has been pressed.

ParameterTypeDescription
indexintThe button to query.

Returns bool — The button state.

PressButton(int index)​

public void PressButton(int index)

Presses the given button.

ParameterTypeDescription
indexintThe button to press.

ReleaseButton(int index)​

public void ReleaseButton(int index)

Releases the given button.

ParameterTypeDescription
indexintThe button to release.

ClickButton(int index)​

public void ClickButton(int index)

Presses then releases the given button.

ParameterTypeDescription
indexintThe button to click.

ClickButton(int index, int delay)​

public void ClickButton(int index, int delay)

Presses then releases the given button with the given delay between the actions.

ParameterTypeDescription
indexintThe button to click.
delayintThe delay between the actions.