0

I need to detect if user is performing a paste(Ctrl+V and mouse right click). I am able to detect ctrl+V but I can't detect copy paste from mouse. I am aware of the onPaste event but I need it under the keydown event because I am writing separate logic for many other key combinations. I have condensed this issue into a smaller code snippet below. I want the same alert to trigger if I copy paste using mouse.Thanks in advance

$("#txt1").keydown(function(event){ 

    if(event.ctrlKey && event.keyCode == 86){
        alert("copy paste detected");
    }
}); 
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input type="text" id="txt1"/>
subhrendu
  • 113
  • 1
  • 1
  • 10
  • 1
    Possible duplicate of [How to detect right mouse click + paste using JavaScript?](https://stackoverflow.com/questions/441631/how-to-detect-right-mouse-click-paste-using-javascript) – Terry Feb 22 '19 at 06:57

2 Answers2

0

I don't know whether this answer meets your requirement. May be you can disable right mouse button click by adding oncontextmenu attribute.which will prevent the right-click --> Paste action.

<body oncontextmenu="return false">
text
</body>
-1

$(document).ready(function() {
  $("#txt1").bind({
    copy: function() {
      $('span').text('copy behaviour detected!');
    },
    paste: function() {
      $('span').text('paste behaviour detected!');
    },
    cut: function() {
      $('span').text('cut behaviour detected!');
    }
  });
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input id="txt1" type="text" size="50" value="Copy, paste or cut message here" />
<br>
<span></span>
doğukan
  • 14,001
  • 6
  • 27
  • 47
yougeen
  • 152
  • 11