What is the best way to implement keyboard shortcuts in Phoenix? This is for an app I am working on at lookupnote.io – registration code “student” if you want to give it a try. Feedback wanted!
Uh, keyboard shortcuts for the phoenix server? That seems odd to need, do you have a keyboard hooked up to the server?
However, if you listen for the top-level key events in the DOM then you can listen for what you need to handle them there without overriding keys for, say, inputs.
Yes, in the browser. Thanks!
like control-N to execute something that can already be done by clicking a link or button.
Just register a response function for the keyup event on the DOM.
Also, Ctrl+N might not be overridable in most browsers, it is often the new window button.
That worked really well — thanks!
I use basically that same code to do some hotkey presses myself.
I am really pleased with this solution. Before, in Rails and Angular apps, I used libraries that I didn’t
understand. It is really just a few lines of JS — no mysteries.