Search code examples
javascriptkeycode

how to select only a b c d e f g with keycode on my javascript code


I have this code how select the B letter on my keyboard and I would select the a b c d e f g

I'm sure it's simple to do this but I don't know yet how to select only few letters than one or all

Can you help me change the keycode line?

new PressAndHold({
  duration: 500, 
  keyCode: 66,
  onCancel: () =>  $('#status-bar').removeClass('is-animating'),
  onStart: () => $('#status-bar').addClass('is-animating'),
  onSuccess: () => { 
    $('#status-bar').removeClass('is-animating')
    $('#footer').addClass('is-showing')
  },
  keepAlive: true
});

$('html').click(() => {
  $('#footer').removeClass('is-showing');
})

Solution

  • Put it in a loop?

    for (let i = 0; i < 7; i++) {
        new PressAndHold({
          duration: 500, 
          keyCode: 65 + i,
          onCancel: () =>  $('#status-bar').removeClass('is-animating'),
          onStart: () => $('#status-bar').addClass('is-animating'),
          onSuccess: () => { 
            $('#status-bar').removeClass('is-animating')
            $('#footer').addClass('is-showing')
          },
          keepAlive: true
        });
    }
    
    $('html').click(() => {
      $('#footer').removeClass('is-showing');
    })
    
    
    $('html').click(() => {
      $('#footer').removeClass('is-showing');
    })