-
Notifications
You must be signed in to change notification settings - Fork 33
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
Question - SDL_GetKeyboardState #34
Comments
I don't know. |
@AlesLulak Here I tried to reimplement the example code from your link as close as I could: State = LibSDL.get_keyboard_state(nil)
loop do # You're gonna need a loop anyway. But want to avoid reassignments to a constant.
if State[LibSDL::Scancode::RETURN.value] > 0
puts "<RETURN> is pressed.\n"
end
if State[LibSDL::Scancode::RIGHT.value] > 0 &&
State[LibSDL::Scancode::UP.value] > 0
puts "Right and Up Keys Pressed.\n"
end
# Omitting boilerplate event polling for termination and window updates.
end And this seems to work like a charm pretty much how it would in C. But you'd probably want to rewrite it with Crystal-specific approach to avoid unsafe pointer access or maybe just use the sdl.cr's own safer methods as shown in samples. |
@ysbaddaden Looking at I don't know enough about this myself to advice, but here are some references to ponder upon: |
For example the clang bindings are automatically generated. |
Sounds interesting but I have my doubts about portability. Still, my expertise is no good at this specific level. |
@Erquint Generating bindings from headers automatically can only help with portability: they'd always be adapted to the actual headers on the target, which is much nicer than static headers generated from a single set of headers (x86_64-linux-gnu). |
I just wonder why SDL won't store that array of effectively boolean UInt8s as a BitArray instead to vacuum that 7-bit padding… |
Is it possible to use SDL_GetKeyboardState?
I tried to get it work by
LibSDL.get_keyboard_state(nil)
but I was unsuccessful.The text was updated successfully, but these errors were encountered: