0

Had a look before asking, but could not find anything close that was recently answered.

New to Javascript; is it possible to create a function that can trigger when a button is clicked so the keyboard shortcut CMD+SHIFT+4 is 'pressed'.

TLDR; I am trying to create a button with a onClick event, that when pressed will allow users to screenshot to clipboard.

I will then have another button to 'press' CMD+V to paste the screenshot.

Any help is appreciated! :)

  • 1
    You cannot prevent the screenshot tool in MacOS. It is happening in the OS, not the browser. – evolutionxbox Dec 27 '21 at 23:37
  • @evolutionxbox - I understand the tool is macOS based, I am asking if the keyboard shortcut can be triggered with Javascript. – destinedtolearn Dec 27 '21 at 23:39
  • Right - I misread the question, but this would be a huge security issue if you were able to trigger other features of the operating system via `JavaScript` in a browser, so this is definitely not possible. Unless you're trying to take a screenshot of the page then I think there might be libraries that allow you to do that, although might not be something that's supported out of the box. – goto Dec 27 '21 at 23:43
  • @user17776855 key presses can be simulated, but it won't be passed to the OS. – evolutionxbox Dec 27 '21 at 23:44
  • Thanks @JohnMontgomery, that does and it correlates with the answer provided below too. – destinedtolearn Dec 27 '21 at 23:44

1 Answers1

2

This is not possible from within the browser because it would create severe security issues if a website could "dictate" which keys are pressed. Imagine a website would open Finder and start deleting files...

Lukas
  • 198
  • 4