Pricing Blog

Keyup event

  • nathandh.-1270251774095392828

    nathandh

    1 year ago

    I see the keyup and keydown events as options in the menu, but where do I specify which key being pressed?
  • Tod-1270251775445831742

    Tod

    1 year ago

    Great energy @nathandh! Your continuous contribution to the toddle Community just made you advance to Community Level 2!
  • tomthebigtree-1270256076364976199

    Tom Ireland

    1 year ago

    To specify the key being pressed, you'll want to work this into the event actions. For example, if you wanted something to happen when you press Enter, you'd want to specify a switch. You can use formula with If to say (as an example) "If event > key equals Enter do some action" e.g. hide an element/component on the page.

    The challenge is actually listening to the event. If memory serves me correctly, you'll need to set the top level page div to be focused on load, so you'll need to specify a tabindex of 0 and set an id for the div. On page load, you have a focus event that gets the id of the div to focus it. Then when you hit the key, it should work as expected.

    Try setting up a variable first and link it to a a text element so that you can see that the key is changing when you press it. Then you can work on the logic for specific key presses.
    👏🏼1
  • tomthebigtree-1270259412010926100

    Tom Ireland

    1 year ago

  • lucasg-1270378853302407292

    Lucas G

    1 year ago

    Key events return the key pressed. It doesn't specify any key. You take the appropriate action by listening for the specific key you want as Tom explained
    🧠1
  • nathandh.-1270387657020805162

    nathandh

    1 year ago

    Ohhhh that makes a lot of sense, thanks @Lucas G !
  • So if I listen for a keydown, I could say if key == Esc, do this action, correct?
  • lucasg-1270387935115743384

    Lucas G

    1 year ago

    You got it