Source Code:
(back to article)
Submit
Result:
Report an issue
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Custom Hotkeys Example</title> <script> document.addEventListener('DOMContentLoaded', function () { let ctrlPressed = false; document.addEventListener('keydown', function(event) { if (event.key === "Control") { ctrlPressed = true; } if (event.key === "s" && ctrlPressed) { alert('Saving your progress!'); event.preventDefault(); // Prevent default to stop other actions like browser shortcuts } }); document.addEventListener('keyup', function(event) { if (event.key === "Control") { ctrlPressed = false; } }); }); </script> </head> <body> <p>Press <strong>Ctrl + S</strong> to simulate a save action.</p> </body> </html>