How to disable right-clicking

How can I disable right-clicking on my Chirpy themed website? I added the following code to disable right-click and certain key combinations (F12 and Alt), but it isn’t working. It worked while using another theme, Hydure. What could be the issue with Chirpy, and how can I fix it?

Here’s the code I used in _includes/disablerightclick.html:

<!-- https://github.com/ishithemes/disablerightclick/blob/f34528a9e1d1da64d14e3ec8a599817001fdaa01/index.html -->

<script type="text/javascript">
    document.onkeydown = function (event) {
         event = (event || window.event);
         if (event.keyCode == 123 || event.keyCode == 18)
         {
               return false;
         }
    }
    document.addEventListener('contextmenu', event => event.preventDefault());
</script>