JavaScript How to bind a keyboard shortcut to the play and pause controls of the html audio element bind keyboard shortcut javascript,bind keyboard shortcut,bind keyboard shortcut

This is what I thought should work but it doesn't. I'm am using unicode 112 for the "p" key and 115 for "s".

var audio = document.getElementById("lessonTrack");
window.addEventListener("keypress", playPauseKb, false);

function playPauseKb() {
  var x = event.keycode;
  if (x == 112) {
    audio.play();
  }
  else if (x == 115) {
    audio.pause();
  }
}
Answer:1

Try the following: Looks like you have the wrong call to keyCode, javascript is case sensitive so keycode is not the same as keyCode

var audio = document.getElementById("lessonTrack");
window.addEventListener("keydown", function(e) {
var x = e.keyCode;
if (x === 80) { // pressed 'p'
  audio.play();
} else if (x === 83) { // pressed 's'
  audio.pause();
}
});
Answer:2

Im getting error on using Google API. having right to connect with Google Drive and add new sheet and insert data into it. It was working till yesterday but when i run the application today. Im ...

Im getting error on using Google API. having right to connect with Google Drive and add new sheet and insert data into it. It was working till yesterday but when i run the application today. Im ...

  1. google drive error creating copy
  2. google drive error accessing folder contents
  3. google drive error 404
  4. google drive error 403
  5. google drive error 401
  6. google drive error 1603
  7. google drive error making copy
  8. google drive error 500
  9. google drive error 400
  10. google drive error rendering shape
  11. google drive error message
  12. google drive error playing video
  13. google drive error unusual traffic
  14. google drive error uploading
  15. google drive error d41d
  16. google drive error a synced folder is missing
  17. google drive error unable to load file
  18. google drive error reload
  19. google drive error can't open file
  20. google drive error 503

I have an ExtJS application and some different environments (local machine, development, production-like test environment, and production). The ExtJS application is backed by a Java backend which is ...

I have an ExtJS application and some different environments (local machine, development, production-like test environment, and production). The ExtJS application is backed by a Java backend which is ...

I'm making a very unique progress bar that visually looks like a glass orb filling up with liquid. Unfortunately, because of the rounded shape, the traditional method of modifying the height doesn't ...

I'm making a very unique progress bar that visually looks like a glass orb filling up with liquid. Unfortunately, because of the rounded shape, the traditional method of modifying the height doesn't ...

I have a menu like : <ul> <li> <a class="scroll-to" href="#one">one</a> </li> <li> <a class="scroll-to" href="#two">two</a> ...

I have a menu like : <ul> <li> <a class="scroll-to" href="#one">one</a> </li> <li> <a class="scroll-to" href="#two">two</a> ...

  1. jquery class active
  2. jquery class active in menu
  3. jquery class active li
  4. jquery class active event
  5. jquery active class on click
  6. jquery active class based on url
  7. jquery active class add and remove
  8. jquery active class on scroll
  9. jquery active class toggle
  10. jquery active class remove
  11. jquery active class not working
  12. jquery active class w3schools
  13. jquery active class index
  14. jquery active class add
  15. jquery active class navigation
  16. jquery active class bootstrap
  17. jquery active class url
  18. jquery active class button
  19. jquery active class css
  20. jquery check class active