Scenic Not Receiving Click Events

I can’t seem to get click events in my scenic code. I’m using scenic 0.9.0 and scenic_driver_glfw 0.9.0. I’m on a Macbook with glfw 3.2.1 and glew 2.1.0. Elixir 1.7.4, OTP 21.

The simplest reproduction I have so far is that I run mix home, cd home and then I edit the lib/scenes/home.ex and I add:

  def handle_input(event, _context, state) do
    require Logger "#{inspect(event)}"
    {:noreply, state}

Now if I start the app I get log output like:

12:17:17.036 [info]  {:viewport_enter, {329.19140625, 571.24609375}}
12:17:18.780 [info]  {:key, {"A", :press, 0}}
12:17:18.781 [info]  {:codepoint, {"a", 0}}
12:17:18.879 [info]  {:key, {"A", :release, 0}}
12:17:19.375 [info]  {:key, {"S", :press, 0}}

But clicking (left or right click) creates no log entries at all.

For any input that is position dependent (i.e. cursor input) you need to have a target to receive the input. Try adding this to your graph (you can add it to the end of the @graph definition):

  |> rectangle({100, 100}, translate: {200, 200}, fill: :white)

Now if you hover over that rectangle you should see log statements like:

07:32:58.105 [info]  {:cursor_pos, {284.18359375, 284.765625}}
07:32:58.138 [info]  {:cursor_pos, {293.81640625, 294.19140625}}
07:32:58.170 [info]  {:cursor_pos, {297.4296875, 299.546875}}

If you want to capture cursor position for the whole screen then you can create a transparent rectangle that covers the entire viewport (here’s a semi real-life example of that from some of my code)

I would expect to see cursor_enter events as well but you may need to call Scenic.ViewPort.capture_input/2 for that.

1 Like

Thanks @axelson! I tried that out and it works perfectly. And once I knew what to google for, it’s right there in the docs.

I just didn’t realize that a Scene did not act like a position-based input on its own. I think clear rectangle over my whole viewport will work great for my use-case (a pixel-y game for my son).


Thanks again @axelson, this helped get me over a hump and now I have a working snake game (following the basic structure of and it works on the 7" raspberry pi touch screen so my son can play it tomorrow.

1 Like

Awesome! I’m glad that you got it to work. That sounds like a nice fun project! Awesome that it’s working on Nerves too.