On þri 10.nóv 2015 12:03, Páll Haraldsson wrote:
> The only game library I know available to Julia is kind of an overkill..:
>
>
https://github.com/zyedidia/SFML.jl
>
> But this is something (a wrapper for a C++ game library) they have to
> deal with (and much more..) and you could even let a joystick [button]
> exit your loop..
You could use this or someone could extract (only) the low-level
keyboard code..:
Ironically I could get the library installed, got some spinning graphics
examples in a Window, but couldn't get checking keyboard status to work
at first :)
Just follow the main README, also "install the package libsfml-dev which
will also install all dependencies" (that are 46 MB) if on Linux. On
Windows everything seems handled, and I also saw some OS X specific code.
Anyway, after trying this example also (also copy-pasting it to the REPL):
https://github.com/zyedidia/SFML.jl/blob/master/examples/Graphics/pong.jl
I got this to work:
[This works for me on Linux, after the graphics window is gone]
#38=left SHIFT, see the file above
julia> is_key_pressed(38)
false
julia> is_key_pressed(38) #while pressing left SHIFT
true
https://github.com/zyedidia/SFML.jl/blob/master/src/julia/Window/keyboard.jl
function is_key_pressed(key::Int)
return ccall((:sfKeyboard_isKeyPressed, libcsfml_window), Int32,
(Int32,), key) == 1
end
baremodule KeyCode
const UNKNOWN = -1
const A = 0
const B = 1
[..]
First I made an error with just copy-pasting this:
julia> ccall((:sfKeyboard_isKeyPressed, libcsfml_window), Int32,
(Int32,), key) == 1
ERROR: UndefVarError: key not defined
in anonymous at no file
This still doesn't work (while the is_key_pressed(38) function works
because of libcsfml_window that is not avaiable to me from the REPL):
julia> ccall((:sfKeyboard_isKeyPressed, libcsfml_window), Int32,
(Int32,), 38) == 1
ERROR: UndefVarError: libcsfml_window not defined
in anonymous at no file