Disable different keyboard short cuts and clicks using Javascript and JQuery

Hi,

I want to disable different clicks on website and keyboard shortcuts.

I found example on google regarding disable right key,disable full page etc.

I am looking for any jquery or javascript library for below option

[1]. Disable Right Click
[2]. Disable Ctrl+c
[3]. Disable Ctrl+v
[4]. Disable Ctrl+x
[5]. Disable Ctrl+s
[6]. Disable Ctrl+p
[7]. Disable Ctrl+w
[8]. Disable Ctrl+u
[9]. Disable Ctrl+a
[10]. Disable Ctrl+z

Any idea?

-Thanks

Can I ask why you want to do this, given it will make life difficult or impossible for anybody keyboarding because they can’t use a mouse?

2 Likes

Disable the context menu:

document.addEventListener('contextmenu', event => {
  event.preventDefault()
})

Disable essential hotkeys:

document.body.addEventListener('keydown', event => {
  if (event.ctrlKey && 'cvxspwuaz'.indexOf(event.key) !== -1) {
    event.preventDefault()
  }
})

BTW I think you forgot ctrl+r to prevent the user from conveniently reloading the page. No seriously, don’t do that. ^^

Hi,

I will not make use of all options to disable but some shortcuts and clicks.

Where I will find details documentation for implementation with require jquery library files.

Hi “m3g4p0p” , I am not getting how this will work from your example code.

How this example code will work for different shortcuts.

Any idea?

I added a keydown event listener to the whole body. Inside the handler function, I checked whether the control key is pressed (event.ctrlKey) and the actual .key is one of cvxspwuaz, and if so, prevent the default action (which would be copy/pasting etc.). Here’s a fiddle.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.