Q: I do not want to show alert message when I prevent users pressing Ctrl and P How can I hide JavaScript's behavior from the user when I prohibit printing?
I was able to prevent the print button from being pressed on that web page by writing the following inside the head tag of the html file:
    <script type="text/javascript">
    document.onkeydown = keys;
    function keys()
    {
   switch (event.keyCode)
       {
        case 82: // Ctrl + R
        if( event.ctrlKey )
        {
        event.keyCode = 0;
        return false;
        }
        case 80: // Ctrl + P
        if( event.ctrlKey )
        {
        event.keyCode = 0;
        alert('Hello.'); //If this code was none, Ctrl and P can be executed,
        return false;
        }
        break;
       }
    }
    </script>

This Ctrl+P is strange.
If I do not intervene something before
   return false;

such as
   alert();

the print screen will appear.
However like
    case 82: // Ctrl + R
    if( event.ctrlKey )
    {
    event.keyCode = 0; 
    return false; //without alert codes,this code can be executed.
    }

The script can be executed without alert codes.It is strange thing for me.
If an alert message is seen, the user will easily see that it is running in JavaScript or something, so if possible, I want something invisible to the user side;
What should I do?
Do I have to show alert message to user like:
    alert('Please do not print.');

I want some help.Thanks.

A: The simplest and most standard way to implement this is with Event#preventDefault:
window.addEventListener('keydown', (e) => {
    if (e.key === 'p' && e.ctrlKey) {
        e.preventDefault()
    }
})

