wslでnerves その41

# 概要
wsl(wsl2じゃない)でnervesやってみる。
qemu(x86_64エミュレータ、ラズパイじゃない)でやってみた。
生成したnerves_livebook.imgを、QEMUで起動してテストしてみた。
GPIOが無いので、マウスを認識できる様にする。
InputEvent を使ってみる。
練習問題、やってみた。


# 練習問題
Livebookで、マウスのデータを取れ。

# 写真

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/18104/f14a9a12-abe4-86e1-bcbb-6aff804e3146.png)

# サンプルコード

```
defmodule Mouse do
	use GenServer
	def init(state) do
		InputEvent.start_link("/dev/input/event2")
		{:ok, state}
	end
	def handle_info(message, state) do
		IO.puts(inspect(message))
		{:noreply, state}
	end
end

GenServer.start(Mouse, [])


```

# 実行結果

```

{:ok, #PID<0.3723.0>}
{:input_event, "/dev/input/event2", [{:ev_rel, :rel_x, -127}, {:ev_rel, :rel_y, 127}]}
{:input_event, "/dev/input/event2", [{:ev_rel, :rel_x, -127}, {:ev_rel, :rel_y, 127}]}
{:input_event, "/dev/input/event2", [{:ev_rel, :rel_x, -50}, {:ev_rel, :rel_y, 127}]}
{:input_event, "/dev/input/event2", [{:ev_rel, :rel_y, 54}]}
{:input_event, "/dev/input/event2", [{:ev_rel, :rel_x, 4}, {:ev_rel, :rel_y, -36}]}
{:input_event, "/dev/input/event2", [{:ev_rel, :rel_x, 1}, {:ev_rel, :rel_y, -12}]}
{:input_event, "/dev/input/event2", [{:ev_rel, :rel_x, 4}, {:ev_rel, :rel_y, -32}]}
{:input_event, "/dev/input/event2", [{:ev_rel, :rel_x, 1}, {:ev_rel, :rel_y, -10}]}
{:input_event, "/dev/input/event2", [{:ev_rel, :rel_x, 4}, {:ev_rel, :rel_y, -36}]}
{:input_event, "/dev/input/event2", [{:ev_rel, :rel_x, 2}, {:ev_rel, :rel_y, -23}]}
{:input_event, "/dev/input/event2", [{:ev_rel, :rel_x, 1}, {:ev_rel, :rel_y, -11}]}
{:input_event, "/dev/input/event2", [{:ev_rel, :rel_y, -4}]}
{:input_event, "/dev/input/event2", [{:ev_rel, :rel_y, 2}]}
{:input_event, "/dev/input/event2", [{:ev_rel, :rel_y, 2}]}
{:input_event, "/dev/input/event2", [{:ev_rel, :rel_y, 2}]}
{:input_event, "/dev/input/event2", [{:ev_rel, :rel_y, 2}]}
{:input_event, "/dev/input/event2", [{:ev_rel, :rel_y, 2}]}
{:input_event, "/dev/input/event2", [{:ev_rel, :rel_y, 1}]}
{:input_event, "/dev/input/event2", [{:ev_rel, :rel_y, 1}]}
{:input_event, "/dev/input/event2", [{:ev_rel, :rel_x, -1}]}
{:input_event, "/dev/input/event2", [{:ev_rel, :rel_y, 2}]}
{:input_event, "/dev/input/event2", [{:ev_rel, :rel_x, -1}, {:ev_rel, :rel_y, 2}]}
{:input_event, "/dev/input/event2", [{:ev_rel, :rel_y, 1}]}
{:input_event, "/dev/input/event2", [{:ev_rel, :rel_x, -1}, {:ev_rel, :rel_y, 2}]}
{:input_event, "/dev/input/event2", [{:ev_rel, :rel_y, 1}]}
{:input_event, "/dev/input/event2", [{:ev_rel, :rel_y, 1}]}
{:input_event, "/dev/input/event2", [{:ev_rel, :rel_y, 1}]}
{:input_event, "/dev/input/event2", [{:ev_rel, :rel_x, -2}, {:ev_rel, :rel_y, 2}]}
{:input_event, "/dev/input/event2", [{:ev_rel, :rel_x, -5}, {:ev_rel, :rel_y, 8}]}
{:input_event, "/dev/input/event2", [{:ev_rel, :rel_x, -2}, {:ev_rel, :rel_y, 3}]}
{:input_event, "/dev/input/event2", [{:ev_rel, :rel_x, -1}, {:ev_rel, :rel_y, 2}]}
{:input_event, "/dev/input/event2", [{:ev_rel, :rel_y, 1}]}
{:input_event, "/dev/input/event2", [{:ev_rel, :rel_x, -1}]}
{:input_event, "/dev/input/event2", [{:ev_rel, :rel_y, -2}]}
{:input_event, "/dev/input/event2", [{:ev_rel, :rel_y, -7}]}
{:input_event, "/dev/input/event2", [{:ev_rel, :rel_y, -5}]}
{:input_event, "/dev/input/event2", [{:ev_rel, :rel_y, -3}]}
{:input_event, "/dev/input/event2", [{:ev_rel, :rel_y, -2}]}
{:input_event, "/dev/input/event2", [{:ev_rel, :rel_x, 1}, {:ev_rel, :rel_y, -2}]}
{:input_event, "/dev/input/event2", [{:ev_rel, :rel_x, 1}, {:ev_rel, :rel_y, -1}]}
{:input_event, "/dev/input/event2", [{:ev_rel, :rel_x, 3}, {:ev_rel, :rel_y, -2}]}
{:input_event, "/dev/input/event2", [{:ev_rel, :rel_x, 4}, {:ev_rel, :rel_y, -1}]}
{:input_event, "/dev/input/event2", [{:ev_rel, :rel_x, 2}, {:ev_rel, :rel_y, -1}]}
{:input_event, "/dev/input/event2", [{:ev_rel, :rel_x, 3}, {:ev_rel, :rel_y, -1}]}
{:input_event, "/dev/input/event2", [{:ev_rel, :rel_x, 1}]}
{:input_event, "/dev/input/event2", [{:ev_rel, :rel_y, -1}]}
{:input_event, "/dev/input/event2", [{:ev_rel, :rel_x, 7}, {:ev_rel, :rel_y, -1}]}
{:input_event, "/dev/input/event2", [{:ev_rel, :rel_x, 6}]}
{:input_event, "/dev/input/event2", [{:ev_rel, :rel_x, 8}]}
{:input_event, "/dev/input/event2", [{:ev_rel, :rel_x, 8}, {:ev_rel, :rel_y, 1}]}
{:input_event, "/dev/input/event2", [{:ev_rel, :rel_x, 1}]}
{:input_event, "/dev/input/event2", [{:ev_rel, :rel_y, 1}]}
{:input_event, "/dev/input/event2", [{:ev_rel, :rel_x, 1}]}
{:input_event, "/dev/input/event2", [{:ev_rel, :rel_x, 1}, {:ev_rel, :rel_y, 2}]}
{:input_event, "/dev/input/event2", [{:ev_rel, :rel_y, 3}]}
{:input_event, "/dev/input/event2", [{:ev_rel, :rel_y, 3}]}
{:input_event, "/dev/input/event2", [{:ev_rel, :rel_y, 3}]}
{:input_event, "/dev/input/event2", [{:ev_rel, :rel_y, 4}]}
{:input_event, "/dev/input/event2", [{:ev_rel, :rel_y, 4}]}
{:input_event, "/dev/input/event2", [{:ev_rel, :rel_y, 5}]}
{:input_event, "/dev/input/event2", [{:ev_rel, :rel_y, 2}]}
{:input_event, "/dev/input/event2", [{:ev_rel, :rel_y, 2}]}
{:input_event, "/dev/input/event2", [{:ev_rel, :rel_x, -1}, {:ev_rel, :rel_y, 1}]}
{:input_event, "/dev/input/event2", [{:ev_rel, :rel_x, -1}]}
{:input_event, "/dev/input/event2", [{:ev_rel, :rel_x, -1}]}
{:input_event, "/dev/input/event2", [{:ev_rel, :rel_x, -3}, {:ev_rel, :rel_y, 1}]}
{:input_event, "/dev/input/event2", [{:ev_rel, :rel_x, -2}, {:ev_rel, :rel_y, 1}]}
{:input_event, "/dev/input/event2", [{:ev_rel, :rel_x, -1}]}
{:input_event, "/dev/input/event2", [{:ev_rel, :rel_x, -2}, {:ev_rel, :rel_y, 1}]}
{:input_event, "/dev/input/event2", [{:ev_rel, :rel_y, 1}]}
{:input_event, "/dev/input/event2", [{:ev_rel, :rel_x, -1}]}
{:input_event, "/dev/input/event2", [{:ev_rel, :rel_x, -1}]}
{:input_event, "/dev/input/event2", [{:ev_rel, :rel_x, -1}, {:ev_rel, :rel_y, -1}]}
{:input_event, "/dev/input/event2", [{:ev_rel, :rel_x, -1}, {:ev_rel, :rel_y, -2}]}
{:input_event, "/dev/input/event2", [{:ev_rel, :rel_x, -1}, {:ev_rel, :rel_y, -1}]}
{:input_event, "/dev/input/event2", [{:ev_rel, :rel_y, -1}]}
{:input_event, "/dev/input/event2", [{:ev_rel, :rel_y, -1}]}
{:input_event, "/dev/input/event2", [{:ev_rel, :rel_y, -2}]}
{:input_event, "/dev/input/event2", [{:ev_rel, :rel_y, -3}]}
{:input_event, "/dev/input/event2", [{:ev_rel, :rel_y, -4}]}
{:input_event, "/dev/input/event2", [{:ev_rel, :rel_y, -7}]}
{:input_event, "/dev/input/event2", [{:ev_rel, :rel_y, -3}]}
{:input_event, "/dev/input/event2", [{:ev_rel, :rel_x, 5}, {:ev_rel, :rel_y, -4}]}
{:input_event, "/dev/input/event2", [{:ev_rel, :rel_x, 3}, {:ev_rel, :rel_y, -2}]}
{:input_event, "/dev/input/event2", [{:ev_rel, :rel_x, 2}, {:ev_rel, :rel_y, -2}]}
{:input_event, "/dev/input/event2", [{:ev_rel, :rel_x, 2}, {:ev_rel, :rel_y, -2}]}
{:input_event, "/dev/input/event2", [{:ev_rel, :rel_x, 3}, {:ev_rel, :rel_y, -3}]}
{:input_event, "/dev/input/event2", [{:ev_rel, :rel_x, 5}, {:ev_rel, :rel_y, -3}]}
{:input_event, "/dev/input/event2", [{:ev_rel, :rel_x, 7}, {:ev_rel, :rel_y, -5}]}
{:input_event, "/dev/input/event2", [{:ev_rel, :rel_x, 4}, {:ev_rel, :rel_y, -3}]}
{:input_event, "/dev/input/event2", [{:ev_rel, :rel_x, 2}, {:ev_rel, :rel_y, -1}]}
{:input_event, "/dev/input/event2", [{:ev_rel, :rel_x, 2}, {:ev_rel, :rel_y, -2}]}
{:input_event, "/dev/input/event2", [{:ev_rel, :rel_x, 2}, {:ev_rel, :rel_y, -2}]}
{:input_event, "/dev/input/event2", [{:ev_rel, :rel_x, 2}]}
{:input_event, "/dev/input/event2", [{:ev_rel, :rel_x, 4}, {:ev_rel, :rel_y, -5}]}
{:input_event, "/dev/input/event2", [{:ev_rel, :rel_x, 1}, {:ev_rel, :rel_y, -5}]}
{:input_event, "/dev/input/event2", [{:ev_rel, :rel_x, 2}, {:ev_rel, :rel_y, -2}]}
{:input_event, "/dev/input/event2", [{:ev_rel, :rel_x, 2}, {:ev_rel, :rel_y, -3}]}
{:input_event, "/dev/input/event2", [{:ev_rel, :rel_y, -1}]}
{:input_event, "/dev/input/event2", [{:ev_rel, :rel_x, 2}, {:ev_rel, :rel_y, -1}]}
{:input_event, "/dev/input/event2", [{:ev_rel, :rel_x, 1}, {:ev_rel, :rel_y, -3}]}
{:input_event, "/dev/input/event2", [{:ev_rel, :rel_x, 4}, {:ev_rel, :rel_y, -6}]}
{:input_event, "/dev/input/event2", [{:ev_rel, :rel_x, 12}, {:ev_rel, :rel_y, -11}]}
{:input_event, "/dev/input/event2", [{:ev_rel, :rel_x, 7}, {:ev_rel, :rel_y, -6}]}
{:input_event, "/dev/input/event2", [{:ev_rel, :rel_x, 4}, {:ev_rel, :rel_y, -3}]}
{:input_event, "/dev/input/event2", [{:ev_rel, :rel_x, 4}, {:ev_rel, :rel_y, -2}]}
{:input_event, "/dev/input/event2", [{:ev_rel, :rel_x, 6}, {:ev_rel, :rel_y, -4}]}
{:input_event, "/dev/input/event2", [{:ev_rel, :rel_x, 2}, {:ev_rel, :rel_y, -3}]}
{:input_event, "/dev/input/event2", [{:ev_rel, :rel_y, -2}]}
{:input_event, "/dev/input/event2", [{:ev_rel, :rel_x, 2}, {:ev_rel, :rel_y, -1}]}
{:input_event, "/dev/input/event2", [{:ev_rel, :rel_y, -2}]}
{:input_event, "/dev/input/event2", [{:ev_rel, :rel_x, 2}, {:ev_rel, :rel_y, -3}]}
{:input_event, "/dev/input/event2", [{:ev_rel, :rel_x, 2}, {:ev_rel, :rel_y, -4}]}
{:input_event, "/dev/input/event2", [{:ev_rel, :rel_x, 2}, {:ev_rel, :rel_y, -2}]}
{:input_event, "/dev/input/event2", [{:ev_rel, :rel_y, -2}]}
{:input_event, "/dev/input/event2", [{:ev_rel, :rel_x, 1}, {:ev_rel, :rel_y, -1}]}
{:input_event, "/dev/input/event2", [{:ev_rel, :rel_x, 1}, {:ev_rel, :rel_y, -1}]}
{:input_event, "/dev/input/event2", [{:ev_rel, :rel_x, 1}, {:ev_rel, :rel_y, -2}]}
{:input_event, "/dev/input/event2", [{:ev_rel, :rel_x, 2}, {:ev_rel, :rel_y, -4}]}
{:input_event, "/dev/input/event2", [{:ev_rel, :rel_x, 1}, {:ev_rel, :rel_y, -1}]}
{:input_event, "/dev/input/event2", [{:ev_rel, :rel_x, 1}, {:ev_rel, :rel_y, -2}]}
{:input_event, "/dev/input/event2", [{:ev_rel, :rel_y, -2}]}
{:input_event, "/dev/input/event2", [{:ev_rel, :rel_x, 2}, {:ev_rel, :rel_y, -5}]}
{:input_event, "/dev/input/event2", [{:ev_rel, :rel_x, 2}, {:ev_rel, :rel_y, -2}]}
{:input_event, "/dev/input/event2", [{:ev_rel, :rel_x, 1}, {:ev_rel, :rel_y, -3}]}
{:input_event, "/dev/input/event2", [{:ev_rel, :rel_x, 2}, {:ev_rel, :rel_y, -4}]}
{:input_event, "/dev/input/event2", [{:ev_rel, :rel_x, 11}, {:ev_rel, :rel_y, -23}]}
{:input_event, "/dev/input/event2", [{:ev_rel, :rel_x, 7}, {:ev_rel, :rel_y, -15}]}
{:input_event, "/dev/input/event2", [{:ev_rel, :rel_x, 3}, {:ev_rel, :rel_y, -9}]}
{:input_event, "/dev/input/event2", [{:ev_rel, :rel_x, 3}, {:ev_rel, :rel_y, -4}]}
{:input_event, "/dev/input/event2", [{:ev_rel, :rel_x, 2}, {:ev_rel, :rel_y, -2}]}
{:input_event, "/dev/input/event2", [{:ev_rel, :rel_y, -1}]}
{:input_event, "/dev/input/event2", [{:ev_rel, :rel_y, -1}]}
{:input_event, "/dev/input/event2", [{:ev_rel, :rel_x, 2}, {:ev_rel, :rel_y, -4}]}
{:input_event, "/dev/input/event2", [{:ev_rel, :rel_y, -1}]}
{:input_event, "/dev/input/event2", [{:ev_rel, :rel_x, 1}, {:ev_rel, :rel_y, -3}]}
{:input_event, "/dev/input/event2", [{:ev_rel, :rel_x, 2}, {:ev_rel, :rel_y, -2}]}
{:input_event, "/dev/input/event2", [{:ev_rel, :rel_x, 2}, {:ev_rel, :rel_y, -3}]}
{:input_event, "/dev/input/event2", [{:ev_rel, :rel_x, 3}, {:ev_rel, :rel_y, -4}]}
{:input_event, "/dev/input/event2", [{:ev_rel, :rel_x, 4}, {:ev_rel, :rel_y, -6}]}
{:input_event, "/dev/input/event2", [{:ev_rel, :rel_x, 6}, {:ev_rel, :rel_y, -9}]}
{:input_event, "/dev/input/event2", [{:ev_rel, :rel_x, 4}, {:ev_rel, :rel_y, -8}]}
{:input_event, "/dev/input/event2", [{:ev_rel, :rel_x, 8}, {:ev_rel, :rel_y, -11}]}
{:input_event, "/dev/input/event2", [{:ev_rel, :rel_x, 10}, {:ev_rel, :rel_y, -18}]}

```


以上。