예제 #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))
}
예제 #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

}
예제 #3
0
파일: sdl.go 프로젝트: genbattle/Go2D
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
}
예제 #4
0
파일: keyboard.go 프로젝트: willemvds/sdl
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),
	}))
}
예제 #5
0
파일: input.go 프로젝트: krig/Go-SDL2
func GetKeyboardState() (ret []byte) {
	var numkeys C.int = 0
	state := C.SDL_GetKeyboardState(&numkeys)
	return C.GoBytes(unsafe.Pointer(state), numkeys)
}