xinput

package module
v0.0.0-...-0559336 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 21, 2016 License: MIT Imports: 2 Imported by: 0

README

xinput

XInput (Xbox 360/Xbox One compatible controller) library for Go on Windows.

Based on: https://github.com/tajtiattila/xinput

Modified version that combines analog input into digital and gives access to modify deadzones.

Requirements

  • Windows 8.1: xinput1_4.dll
  • Windows 7: xinput1_3.dll
  • Windows Vista: xinput9_1_0.dll

Tested on Windows 10 x64.

Installation

go get github.com/Nudua/xinput

Usage

IsLoaded checks if XInput was loaded successfully.

GetState retrieves the state thumbsticks, d-pad, buttons, triggers and digital versions of the analog input.

GetSimpleState retrieves the state thumbsticks, d-pad, buttons and triggers.

SetState sets vibration state.

Deadzones and thresholds for analog inputs

LEFT_THUMB_DEADZONE default '7849' (-32767 to 32767)

RIGHT_THUMB_DEADZONE default '8689' (-32767 to 32767)

TRIGGER_TRESHOLD default '50' (0 to 255)

Example

TODO

Documentation

Index

Constants

View Source
const (
	DPAD_UP        uint = 0x0001
	DPAD_DOWN      uint = 0x0002
	DPAD_LEFT      uint = 0x0004
	DPAD_RIGHT     uint = 0x0008
	START          uint = 0x0010
	BACK           uint = 0x0020
	LEFT_THUMB     uint = 0x0040
	RIGHT_THUMB    uint = 0x0080
	LEFT_SHOULDER  uint = 0x0100
	RIGHT_SHOULDER uint = 0x0200
	BUTTON_A       uint = 0x1000
	BUTTON_B       uint = 0x2000
	BUTTON_X       uint = 0x4000
	BUTTON_Y       uint = 0x8000
)

Digital Input

View Source
const (
	RIGHT_STICK_UP    uint = 0x10000
	RIGHT_STICK_DOWN  uint = 0x20000
	RIGHT_STICK_LEFT  uint = 0x40000
	RIGHT_STICK_RIGHT uint = 0x80000

	LEFT_STICK_UP    uint = 0x100000
	LEFT_STICK_DOWN  uint = 0x200000
	LEFT_STICK_LEFT  uint = 0x400000
	LEFT_STICK_RIGHT uint = 0x800000

	LEFT_TRIGGER  uint = 0x1000000
	RIGHT_TRIGGER uint = 0x2000000
)

Analog to Digital Input

View Source
const CONTROLLER_MAX = 4

CONTROLLER_MAX valid controller numbers are 0-3

Variables

View Source
var (
	// TRIGGER_TRESHOLD Threshold for the left and right triggers (0 to 255)
	TRIGGER_TRESHOLD uint8 = 50

	// LEFT_THUMB_DEADZONE Deadzone for the Left Thumb Stick (-32767 to 32767)
	LEFT_THUMB_DEADZONE int16 = 7849

	// LEFT_THUMB_DEADZONE Deadzone for the Right Thumb Stick (-32767 to 32767)
	RIGHT_THUMB_DEADZONE int16 = 8689
)

Functions

func GetSimpleState

func GetSimpleState(controller uint, state *State) error

GetSimpleState retrieves the current state of the controller excluding analog buttons as digital.

func GetState

func GetState(controller uint, state *State, digitalAnalogButtonState *uint) error

GetState retrieves the current state of the controller including analog buttons as digital. The analog inputs (Thumbsticks and Triggers) will be shifted into digitalAnalogButtonState

func IsDown

func IsDown(digitalAnalogButtonState uint, button uint) bool

IsDown Example: IsDown(allButtonState, DPAD_UP)

func IsLoaded

func IsLoaded() (bool, error)

IsLoaded checks if XInput was successfully loaded. Other functions of the library may be used safely only if it returns no error.

func SetState

func SetState(controller uint, vibration *Vibration) error

SetState sets the vibration for the controller.

Types

type Gamepad

type Gamepad struct {
	Buttons      uint16
	LeftTrigger  uint8
	RightTrigger uint8
	ThumbLX      int16
	ThumbLY      int16
	ThumbRX      int16
	ThumbRY      int16
}

type State

type State struct {
	PacketNumber uint32 // increased for every controller change
	Gamepad      Gamepad
}

type Vibration

type Vibration struct {
	LeftMotorSpeed  uint16
	RightMotorSpeed uint16
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL