Community X.

Connect with other creators, share ideas, give feedback and get the latest product updates.

Jan 25

How to detect a keystroke on the keyboard. ?

Hi,


I want to use spacebar or arrows keyboard press to trigger actions.

How to with Velo or HTML iFrame ?


Thank you!

Ben

2 answers0 replies
1

Hi,


Great question!


You can trigger functions and events on keypress using Velo or writing your own custom code.

In Velo, you can trigger an event using the KeyboardEvent, there is more info about it here: https://www.wix.com/velo/reference/$w/keyboardevent


You can also add custom code to any page of your site or the entire site, you can read about it here: https://support.wix.com/en/article/embedding-custom-code-to-your-site


Here is an example code:

<script>
document.addEventListener("keydown", event => {
  if (event.isComposing || event.keyCode === 83) {
    console.log("this is awesome!");
  }
});
</script>

The specific keycodes can be found here: https://keycode.info/

We don't recommend using this method as we can't troubleshot issue with third party code.


1

Hi Sebi, Thank you for your answer.


$w/keyboardevent works exclusively while the cursor is inside an "input" element, so limits a lot its use.

This will not work, for example, to simply trigger an action on an element with spacebar or arrows press.


As custom code is not recommended (and I'm not an experimented programmer;), that means there is no way to do this in Editor x (and Wix) today.

This represents, it seems to me, a great lack in optimizing the interactivity and responsiveness of a (basic) website.


Is this function part of your short-term development projects?


Thanks very much for your interest. Ben



Editor X

Design your boldest creations.