Hello everyone! I stuck here! So pls explain for me my code

I have the function use $(document).keypress() in jquery. But i don’t understand why when i change value of keycode my function not working

$(document).keypress(function (e) {
    if (e.which === 13) {
        $(".WRAP .CONTENT .CONTENT_INSTRUCTION .current .current_info_car .two_button .Ok_button").on('click', ConfirmOK());
    } 
    if (e.which === 32) {
        $(".WRAP .CONTENT .CONTENT_INSTRUCTION .current .current_info_car .two_button .skip_button").on('click', ConfirmOK());
    }
});

when i change e.which === 83 this code not working

Are you trying to get the S key (83) or s key (115)? Have you tried logging out the event and making sure it’s working and giving you the code you expect?

I would suggest using .key instead of .which (KeyboardEvent.key).

Thanks u so much! i got it , i wrong s key (115) to S(83) and .key not working it’s my function!

What do you mean .key isn’t working? It doesn’t give you the same code but Key Values.

$(document).keypress(function (e) {
  console.log('Key', e.key)
    if (e.key === 'Enter') {
      console.log(e.key)
    } 
    if (e.key === ' ') {
       console.log(e.key)
    }
      if (e.key === 's') {
       console.log(e.key)
    }
});
1 Like

oh! I’m sorry i use .key Values with keycode not use for word! Thanks u for give time and explain for me !

No problem, happy to help.