Example #1
1
func GetKeyboardState() []uint8 {
	var numkeys C.int
	start := C.SDL_GetKeyboardState(&numkeys)
	sh := reflect.SliceHeader{}
	sh.Len = int(numkeys)
	sh.Cap = int(numkeys)
	sh.Data = uintptr(unsafe.Pointer(start))
	return *(*[]uint8)(unsafe.Pointer(&sh))
}
Example #2
0
func Keystate(key string) int {
	if key == "joy1stick1x" {
		makestickopened()
		return int(C.SDL_JoystickGetAxis(joy, 0))
	}
	if key == "joy1stick1y" {
		makestickopened()
		return int(C.SDL_JoystickGetAxis(joy, 1))
	}
	if key == "joy1stick2x" {
		makestickopened()
		return int(C.SDL_JoystickGetAxis(joy, 3))
	}
	if key == "joy1stick2y" {
		makestickopened()
		return int(C.SDL_JoystickGetAxis(joy, 4))
	}
	if key == "joy1a" {
		makestickopened()
		return int(C.SDL_JoystickGetButton(joy, 0))
	}
	var length C.int
	keys := C.SDL_GetKeyboardState(&length)
	return int(*(*byte)(unsafe.Pointer(uintptr(unsafe.Pointer(keys)) + uintptr(str2scancode(key))))) //letter scancodes start at 4

}
Example #3
0
func KeyDown(_key int) bool {
	zero := C.int(0)
	var state = uintptr(unsafe.Pointer(C.SDL_GetKeyboardState(&zero))) + uintptr(_key)
	down := (*uint8)(cast(state))
	if *down == 1 {
		return true
	}
	return false
}
Example #4
0
func GetKeyboardState() []uint8 {
	var n C.int
	s := C.SDL_GetKeyboardState(&n)

	return *(*[]uint8)(unsafe.Pointer(&reflect.SliceHeader{
		Data: uintptr(unsafe.Pointer(s)),
		Len:  int(n),
		Cap:  int(n),
	}))
}
Example #5
0
func GetKeyboardState() (ret []byte) {
	var numkeys C.int = 0
	state := C.SDL_GetKeyboardState(&numkeys)
	return C.GoBytes(unsafe.Pointer(state), numkeys)
}