2019-12-21 06:09:31 -06:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
|
|
|
|
"github.com/veandco/go-sdl2/sdl"
|
|
|
|
)
|
|
|
|
|
|
|
|
func run() (err error) {
|
|
|
|
var window *sdl.Window
|
|
|
|
|
|
|
|
if err = sdl.Init(sdl.INIT_EVERYTHING); err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
defer sdl.Quit()
|
|
|
|
|
|
|
|
window, err = sdl.CreateWindow("Input", sdl.WINDOWPOS_UNDEFINED, sdl.WINDOWPOS_UNDEFINED, 800, 600, sdl.WINDOW_SHOWN)
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
defer window.Destroy()
|
|
|
|
|
|
|
|
running := true
|
|
|
|
for running {
|
|
|
|
for event := sdl.PollEvent(); event != nil; event = sdl.PollEvent() {
|
|
|
|
switch t := event.(type) {
|
2023-11-30 00:59:58 -06:00
|
|
|
case sdl.QuitEvent:
|
2019-12-21 06:09:31 -06:00
|
|
|
running = false
|
2023-11-30 00:59:58 -06:00
|
|
|
case sdl.MouseMotionEvent:
|
2019-12-21 06:09:31 -06:00
|
|
|
fmt.Println("Mouse", t.Which, "moved by", t.XRel, t.YRel, "at", t.X, t.Y)
|
2023-11-30 00:59:58 -06:00
|
|
|
case sdl.MouseButtonEvent:
|
2019-12-21 06:09:31 -06:00
|
|
|
if t.State == sdl.PRESSED {
|
|
|
|
fmt.Println("Mouse", t.Which, "button", t.Button, "pressed at", t.X, t.Y)
|
|
|
|
} else {
|
|
|
|
fmt.Println("Mouse", t.Which, "button", t.Button, "released at", t.X, t.Y)
|
|
|
|
}
|
2023-11-30 00:59:58 -06:00
|
|
|
case sdl.MouseWheelEvent:
|
2019-12-21 06:09:31 -06:00
|
|
|
if t.X != 0 {
|
|
|
|
fmt.Println("Mouse", t.Which, "wheel scrolled horizontally by", t.X)
|
|
|
|
} else {
|
|
|
|
fmt.Println("Mouse", t.Which, "wheel scrolled vertically by", t.Y)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sdl.Delay(16)
|
|
|
|
}
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
if err := run(); err != nil {
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
}
|