aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristine Dodrill <me@christine.website>2017-10-12 23:54:19 -0700
committerChristine Dodrill <me@christine.website>2017-10-12 23:54:45 -0700
commita1c962faa304eee9d6fc30c8c4a4382fbdabcc05 (patch)
tree0b2869e2a8f31a1f1dff558b1e1f48d3769843cf
parent2e7ad18cbac67114f92ca1e1d1dc780ae21ea61f (diff)
downloadx-a1c962faa304eee9d6fc30c8c4a4382fbdabcc05.tar.xz
x-a1c962faa304eee9d6fc30c8c4a4382fbdabcc05.zip
sdl: add joydumpr
-rw-r--r--sdl/joydumpr/main.go36
1 files changed, 36 insertions, 0 deletions
diff --git a/sdl/joydumpr/main.go b/sdl/joydumpr/main.go
new file mode 100644
index 0000000..ad7c657
--- /dev/null
+++ b/sdl/joydumpr/main.go
@@ -0,0 +1,36 @@
+package main
+
+import (
+ "log"
+
+ "github.com/veandco/go-sdl2/sdl"
+)
+
+func main() {
+ if err := sdl.Init(sdl.INIT_EVERYTHING); err != nil {
+ panic(err)
+ }
+ defer sdl.Quit()
+
+ nj := sdl.NumJoysticks()
+ log.Printf("%d joysticks detected", nj)
+
+ for i := 0; i < nj; i++ {
+ j := sdl.JoystickOpen(sdl.JoystickID(i))
+ defer j.Close()
+
+ log.Printf("%d joystick name: %s, %d buttons, %d axes, %d hats", i, j.Name(), j.NumButtons(), j.NumAxes(), j.NumHats())
+
+ for ii := 0; ii < j.NumButtons(); ii++ {
+ log.Printf("%d joystick button %d: %v", i, ii, j.GetButton(ii))
+ }
+
+ for ii := 0; ii < j.NumAxes(); ii++ {
+ log.Printf("%d joystick axis %d: %v", i, ii, j.GetAxis(ii))
+ }
+
+ for ii := 0; ii < j.NumHats(); ii++ {
+ log.Printf("%d joystick hat %d: %v", i, ii, j.GetHat(ii))
+ }
+ }
+}