Creating custom hotkeys

Hello!
Maybe you can help me with my problem. I have a tabbedContainer object in my module. I would like to make custom hotkeys to switch between tabs of this object in the application. The standard functionality doesn't work because of a bug, as I read on the forum. Unfortunately, I don't have enough knowledge of js to solve this case myself. Maybe you can give me a suggestion?

try this:

tabbedContainer1.addEventListener("keydown", function(e) {
  if(!e.repeat){
    console.log(`Key "${e.key}" pressed [event: keydown]`);
  }
  else{
    console.log(`Key "${e.key}" repeating [event: keydown`);
  }
});

the possible event names are: keydown, keyup, beforeinput, input, click

you could also use e.code but this returns the key based on a QUERTY keyboard so if you use a different one you could get the wrong key code. for example, on a normal keyboard Y is above H, but if you use a QUERYZ keyboard Z is above H... in this case when they press Z e.code will return KeyY because that's what is normally there. e.key will return a string consisting of the key pressed, so in the previous example pressing Z on any keyboard layout will always return z.

I've actually never tried this in Retool, so you might need to use document.getElementById() instead of using tabbedContainer1:

var containerElement = document.getElementById('retool-tabbedContainer1');
containerElement.addEventListener("keydown", function(e) {

});

let me know if you end up having to do it this way and need help with the element id (retool-tabbedContainer1 in this case)

1 Like

don't forget to mark something as the solution if your all set or if you figured it out on your own put a reply in here and mark your own message as the solution. it's for others to easily find in the future =) :beers:

@bobthebear this is awesome :pray: And great question, @bwlfd!

2 Likes