Just wanted to share my two cents. You can't completely disable those options but you can limit the ease of usage.
onkeydown
actions are pretty rare from a user standpoint. One could even argue that the only real use case scenario would be, form completion.
Taking that approach the most effective way would be to conditionally disable the event itself with an exception to specific targets, in our case, input
s and textarea
s.
document.onkeydown=function(e){if(!e.target.matches("input")&&!e.target.matches("textarea"))return!1};
A minimal and effective way of implementing this solution is to associate it with the <body>
tag.
In the following example, in addition, I've added other behavior that are usually disabled when thinking of user ability restrictions (eg: user selection, dragging, right-click).
<body onkeydown="if(!event.target.matches('input')&&!event.target.matches('textarea'))return!1" oncontextmenu="return!1" onselectstart="return!1" ondragstart="return!1">