Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Given a *uint8 from state how do I test if a scancode is pressed? #4

Closed
fire opened this issue Jan 16, 2014 · 3 comments
Closed

Given a *uint8 from state how do I test if a scancode is pressed? #4

fire opened this issue Jan 16, 2014 · 3 comments

Comments

@fire
Copy link

fire commented Jan 16, 2014

Given a *uint8 from state how do I test if a scancode is pressed?

http://wiki.libsdl.org/SDL_GetKeyboardState

I can do state := sdl.GetKeyboardState(nil), but then state is a pointer. Should this api be a map so I can test using a key such as SDL_SCANCODE_RETURN?

@fire
Copy link
Author

fire commented Jan 16, 2014

@fire
Copy link
Author

fire commented Jan 16, 2014

import "reflect"

func GetKeyboardState(numkeys *int) []uint8 {
    _numkeys := (*C.int) (unsafe.Pointer(numkeys))
    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))
}

@aqiank
Copy link

aqiank commented Jan 17, 2014

Yeah, that's definitely better usage and safety wise because there's no separate variable to know the length of the array. It's now using the code from dooots . Thanks!

@fire fire closed this as completed Jan 19, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants