Trigger button action using special key

Trigger button action using special key

dsteinbergdsteinberg Posts: 20Questions: 6Answers: 1

Hi, I have read the buttons.buttons.key documentation and cannot figure out how to make this track by keycode for special cases like the "insert" key. How can we trigger a button's action when the "insert" key is pressed? I tried it by keycode, the word "insert", even tried a bunch of ascii escape sequences to no effect.

I'd also like to unmap this key from Keytable/editor - currently it edits the field you've selected, but it ought to just activate a particular button and do nothing else. Keytable offers a .keys configuration option but not a way to keep the default while excluding a single key, seemingly.

Thanks!

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,818Questions: 1Answers: 10,517 Site admin

    How can we trigger a button's action when the "insert" key is pressed?

    What is the keycode for the insert key? My keyboard doesn't actually have that key, so I can't check!

    Normally what I do is:

    $(document).on( 'keyup', function ( e ) {
      console.log( e.keyCode );
    } );
    

    to find out key codes I don't know!

    Allan

  • dsteinbergdsteinberg Posts: 20Questions: 6Answers: 1

    Hi Allan, the code is 45. I usually use this site: http://keycode.info/

    So, adding key: 45 ought to have triggered the button, no?

  • dsteinbergdsteinberg Posts: 20Questions: 6Answers: 1
    Answer ✓

    Aha, just dug through the source for Buttons and found this tricky solution:

    String.fromCharCode(45)

    This worked! May be helpful to add to the documentation :smiley:

  • allanallan Posts: 63,818Questions: 1Answers: 10,517 Site admin

    Thanks for posting back - good to hear you found a solution. I'll get something about that added in.

    Allan

This discussion has been closed.