github.com/egonelbre/exp@v0.0.0-20240430123955-ed1d3aa93911/game/gamepad/example.go (about)

     1  // +build ignore
     2  
     3  package main
     4  
     5  import (
     6  	"fmt"
     7  	"time"
     8  
     9  	"github.com/loov/input/gamepad"
    10  )
    11  
    12  func main() {
    13  	gamepads := gamepad.All{}
    14  
    15  	prev := int16(0)
    16  	for range time.Tick(1 * time.Millisecond) {
    17  		gamepads.Update()
    18  		for i := range gamepads {
    19  			pad := &gamepads[i]
    20  			if !pad.Connected {
    21  				continue
    22  			}
    23  
    24  			if pad.Raw.ThumbLX != prev {
    25  				fmt.Println(time.Now().Nanosecond(), pad.Raw.ThumbLX, pad.Raw.ThumbRX)
    26  				prev = pad.Raw.ThumbLX
    27  			}
    28  		}
    29  	}
    30  }