Click here to Skip to main content
15,887,485 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
jQuery. How can I simulate ctrl + shift + c in jQuery?

What I have tried:

I tried to use this code:
$(this).trigger($.Event("keypress", {keyCode: 17 + 16 + 67}));
Posted
Updated 10-Jul-23 23:13pm

The use of 'keyCode's' is deprecated and was removed from some browsers for security reasons.
Quote:
Deprecated: This feature is no longer recommended. Though some browsers might still support it, it may have already been removed from the relevant web standards, may be in the process of being dropped, or may only be kept for compatibility purposes
- KeyboardEvent: keyCode property[^]

Quote:
You should avoid using this if possible; it's been deprecated for some time. Instead, you should use 'KeyboardEvent.code'


Full tutorial with code is given at - KeyboardEvent: code property[^]

To simulate the CTR SHIFT C -
JavaScript
// Simulate Ctrl + Shift + C
var event = jQuery.Event("keydown");
event.ctrlKey = true;
event.shiftKey = true;
event.which = 67; // Key code for 'C'
$(document).trigger(event);
 
Share this answer
 
It don't work that way !
JavaScript
$(this).trigger($.Event("keypress", {keyCode: 17 + 16 + 67}));

means
JavaScript
$(this).trigger($.Event("keypress", {keyCode: 100}));

You should study: KeyboardEvent keyCode Property[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900