8. Keyboard Shortcuts
HTMX typically triggers off of user clicks but can do so much more. You can assign triggers to keystrokes and commands using the keyup[] value for hx-trigger. For example, the following attribute will show a toast notification when using the ? key anywhere in the body.
hx-trigger="keyup[key=='?'] from:body"
Note that the toast element found in Shared/_Toast.cshtml is only HTML. The toast's target is an HTML element at the bottom of our page.
Try it out!
Question: What other keyboard shortcuts would you like to attach? Try changing the hx-trigger attribute with your own key combinations.
Try pressing the Question Mark (
?) key on your keyboard. Look to the bottom right of your window.