Phoenix key events -- how to ignore modifier keys?

For my hangman game from @pragdave’s course I’d like the Phoenix frontend not to signal the game for all keypresses, only those that are valid alphabetic keys. Is there a way to do limit phx-keyup in this way, or do I need to handle the message in the game backend?

I think it’s best to just handle it in the game code since not sending a message at all could let the timer on the game run out. If the player hits an invalid key like “SHIFT” it shows they are still active and should signal the game as such. I’m still curious if there’s a way to have phx-keyup or phx-keydown only respond to a subset of keys, but for this specific use it’s moot.

1 Like