# Joystick driver for Windows

**URL:** <https://discourse.julialang.org/t/joystick-driver-for-windows/81473>\
**Category:** General Usage\
**Tags:** question\
**Created:** [May 22, 2022, 9:25pm UTC](https://discourse.julialang.org/t/joystick-driver-for-windows/81473 "2022-05-22T21:25:06Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Post date:** [May 22, 2022, 9:25pm UTC](https://discourse.julialang.org/t/joystick-driver-for-windows/81473/1 "2022-05-22T21:25:06Z")

</div>

I am quite happy with the Joystick driver for Linux [GitHub - ufechner7/Joysticks.jl: Joystick interface for Julia](https://github.com/ufechner7/Joysticks.jl) , but now people also want to have it on Windows.

That seams to be difficult. As far as I understand there are two options

1. Use a Windows API, e.g. DirectX
2. Using a cross-platform intermediate library like [SFML](https://de.wikipedia.org/wiki/Simple_and_Fast_Multimedia_Library), [SDL](https://de.wikipedia.org/wiki/Simple_DirectMedia_Layer), [ClanLib](https://de.wikipedia.org/wiki/ClanLib) oder [Allegro](https://de.wikipedia.org/wiki/Allegro_(Programmbibliothek))

As far as I know option one will not work because this is a C++ interface with a lot of proprietary extensions and Julia can only access C libraries directly.

For option two I looked at SDL for which Julia bindings exist, but they are more or less unmaintained and at least one serious bug is in the binding. See: [GitHub - JuliaMultimedia/SimpleDirectMediaLayer.jl: SDL2](https://github.com/JuliaMultimedia/SimpleDirectMediaLayer.jl)

I did not look at SFML, ClanLib or Allegro yet.

Any suggestions how to proceed?

Update: There are bindings for SFML [GitHub - zyedidia/SFML.jl: A binding of the game and multimedia library SFML for Julia](https://github.com/zyedidia/SFML.jl) , but they look unmaintained and cannot be installed on a current Julia version.

Perhaps one more option: [GitHub - chengchingwen/Raylib.jl: Julia wrapper for the raylib videogames programming library](https://github.com/chengchingwen/Raylib.jl)

---

<div class="post-metadata">

**Author:** ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Post date:** [May 22, 2022, 10:02pm UTC](https://discourse.julialang.org/t/joystick-driver-for-windows/81473/2 "2022-05-22T22:02:17Z")

</div>

First finding: The mouse driver example for Raylib works. Next question: Does the joystick support work?  
[https://github-wiki-see.page/m/raysan5/raylib/wiki/raylib-input-system](https://github-wiki-see.page/m/raysan5/raylib/wiki/raylib-input-system)

---

<div class="post-metadata">

**Author:** ![Palli](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/palli/32/3380_2.png) [@Palli](https://discourse.julialang.org/u/Palli)\
**Post date:** [May 22, 2022, 10:06pm UTC](https://discourse.julialang.org/t/joystick-driver-for-windows/81473/3 "2022-05-22T22:06:11Z")

</div>

Note this one installs:

> **[GitHub - JuliaMultimedia/CSFML.jl: Julia bindings for CSFML](https://github.com/JuliaMultimedia/CSFML.jl)**
>
> Julia bindings for CSFML. Contribute to JuliaMultimedia/CSFML.jl development by creating an account on GitHub.

and startup is fast:

```julia
julia> @time using CSFML
  0.592167 seconds (1.17 M allocations: 55.937 MiB, 1.58% gc time, 19.78% compilation time)

```

I’m on Linux so I didn’t test Windows, nor further than this. I believe it’s a replacement.

I did see some PR for the other, and tried to see how far I would get (maybe not a lot of work to fix the rest, if at all needed):

```julia
(v0.7) pkg> add https://github.com/zyedidia/SFML.jl#69d9d1a

```

I could install it but then get some warnings plus:

```julia
julia> @time using SFML
[..]
Something has gone wrong with the SFML installation.
ErrorException("could not load library \"libsfml-graphics\"\nlibGLEW.so.1.10: cannot open shared object file: No such file or directory")
  1.817890 seconds (3.01 M allocations: 151.960 MiB, 1.92% gc time)

```

---

<div class="post-metadata">

**Author:** ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Post date:** [May 22, 2022, 10:12pm UTC](https://discourse.julialang.org/t/joystick-driver-for-windows/81473/4 "2022-05-22T22:12:05Z")

</div>

On Debian you can install the package `libsfml-dev` which will also install all dependencies.

---

<div class="post-metadata">

**Author:** ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Post date:** [May 22, 2022, 10:24pm UTC](https://discourse.julialang.org/t/joystick-driver-for-windows/81473/5 "2022-05-22T22:24:23Z")

</div>

Perhaps [GitHub - JuliaGL/GLFW.jl: Julia interface to GLFW, a multi-platform library for creating windows with OpenGL contexts and managing input and events.](https://github.com/JuliaGL/GLFW.jl) is also an option…

Good load time:

```julia
julia> @time using GLFW
  0.177575 seconds (154.50 k allocations: 10.206 MiB, 36.09% compilation time)

```

See: [GLFW: Input guide](https://www.glfw.org/docs/3.3/input_guide.html#joystick)

---

<div class="post-metadata">

**Author:** ![Palli](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/palli/32/3380_2.png) [@Palli](https://discourse.julialang.org/u/Palli)\
**Post date:** [May 22, 2022, 10:26pm UTC](https://discourse.julialang.org/t/joystick-driver-for-windows/81473/6 "2022-05-22T22:26:23Z")

</div>

Hope the other option CSFML.jl just works for you, because:

Despite (on Ubuntu):

```julia
$ sudo apt-get install libsfml-dev

```

and rm SFML.jl just in case, then again, for me at least:

```julia
(v0.7) pkg> add https://github.com/zyedidia/SFML.jl#69d9d1a
[..]
 Building SFML → `~/.julia/packages/SFML/O6kxz/deps/build.log`
┌ Error: Error building `SFML`: 

[..]
 ERROR: LoadError: UndefVarError: JULIA_HOME not defined
│ Stacktrace:

[..]
│ in expression starting at /home/pharaldsson_sym/.julia/packages/SFML/O6kxz/deps/build.jl:148
│ Downloading SFML...
│ Downloading CSFML...
└ @ Pkg.Operations /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v0.7/Pkg/src/Operations.jl:1068

```

add [GitHub - zyedidia/SFML.jl: A binding of the game and multimedia library SFML for Julia](https://github.com/zyedidia/SFML.jl#69d9d1a)

Something has gone wrong with the SFML installation.  
ErrorException(“could not load library "libsfml-graphics"\nlibGLEW.so.1.10: cannot open shared object file: No such file or directory”)  
5.380880 seconds (3.73 M allocations: 188.123 MiB, 1.73% gc time)

```julia

```

---

<div class="post-metadata">

**Author:** ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Post date:** [May 22, 2022, 10:37pm UTC](https://discourse.julialang.org/t/joystick-driver-for-windows/81473/7 "2022-05-22T22:37:42Z")

</div>

Thanks for investigating!

First success:

```julia
using GLFW

present = GLFW.JoystickPresent(GLFW.JOYSTICK_1)

```

returns `true`

And this also works:

```julia
while true
    axis = GLFW.GetJoystickAxes(GLFW.JOYSTICK_1)
    buttons = GLFW.GetJoystickButtons(GLFW.JOYSTICK_1)
    println(axis, " ", buttons)
    sleep(0.1)
end

```
