Ajaxdone

Ajaxdone

Change not working in Phoenix LiveView for Key HJKL

In Phoenix LiveView example for the snake, I want to change the ArrowLeft/ArrowDown/ArrowUp/ArrowRight to KeyH/KeyJ/HeyK/KeyL, but not working. If I change to F5/F6/F7/F8 it works, here is the code before and after:

Original:

   defp turn(socket, "ArrowLeft"), do: go(socket, :left)
   defp turn(socket, "ArrowDown"), do: go(socket, :down)
   defp turn(socket, "ArrowUp"), do: go(socket, :up)
   defp turn(socket, "ArrowRight"), do: go(socket, :right)

Changed to this, but not working:

   defp turn(socket, "KeyH"), do: go(socket, :left)
   defp turn(socket, "KeyJ"), do: go(socket, :down)
   defp turn(socket, "KeyK"), do: go(socket, :up)
   defp turn(socket, "KeyL"), do: go(socket, :right)

This one works:

   defp turn(socket, "F5"), do: go(socket, :left)
   defp turn(socket, "F6"), do: go(socket, :down)
   defp turn(socket, "F7"), do: go(socket, :up)
   defp turn(socket, "F8"), do: go(socket, :right)

Any idea why it works for Function keys but not A-Z ?

Marked As Solved

idi527

idi527

:waving_hand:

Would probably be h according to KeyboardEvent: key property - Web APIs | MDN. Check what your live view process actually receives.

Where Next?

Popular in Questions Top

nobody
How to bind a phoenix app to a specific ip address? could not find anything about that, nowhere, unfortunately, but for me this is quite...
New
beno
I will often find my self writing things similar to: case some_value do nil -> something() "" -> something() _ -> somethi...
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID<0.412.0> terminating ** (Postgrex.Error) FATAL...
New
shahryarjb
Hello, I have map which I want to convert it to string like this: the map: %{last_name: "tavakkoli", name: "shahryar"} the string I ne...
New
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
New
nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
script
If I have a string “1000 cfu/ml” . I want to remove the characters and / and space . So the string is like this "1000" What is the ...
New
srinivasu
How to handle excepions in elixir? Suppose i have A, B, C ,D, E modules. and each module has get() function. A.get() method will call t...
New
rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list. ...
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New

Other popular topics Top

aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
marius95
Hello everyone, I try to use an Javascript Event Handler in my root.html.leex file. Therefore I created a function in the app.js file: ...
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
johnnyicon
Hi all, I’ve just started learning Elixir and Phoenix Framework, so please pardon my n00bness at this stage. I’m trying to use Postgres...
New
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? Ecto.Repo — Ecto v3.14.0 has exampl...
New
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
dogweather
I wrote this comment on r/haskell, and it’s not popular there. :wink: But I think I’m on to something… Haskell reminds me of Java, and e...
New
vegabook
I’m brand new to Phoenix and I have stripped one of the demo applications to the bone. I just want to get an svg up on the screen. Here i...
New

Latest on Elixir Forum

Elixir Forum

We're in Beta

About us Mission Statement