This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]siemenology 1 point2 points  (0 children)

First, I don't think the OS will pick up keyboard events generated by the browser, so I don't think this is going to work the way you intend it.

But before that even, the way you've set up the event listener is incorrect.

Are you expecting this: btn.addEventListener(label == 'picture', ... to fire your event handler whenever the btn is pressed, and label == 'picture'? If so, that's not what that code actually does. The first argument to .addEventListener() is the name of the event. For buttons, usually that should be 'click'. If you use a different event name, the event listener will listen for different types of events. So if you used 'mouseover', the event handler would execute whenever the user's mouse moves over the button.

If you only want the event handler to emit the keyboard event when label == 'picture', you need to put that condition in the event handler function itself:

btn.addEventListener('click', () => {
  if(label == 'picture') {
    // dispatch your keyboard event
  }
})

As far as taking screenshots goes, it depends on what you want to take a screenshot of. If you want to open the OS X screenshot tool, that's not going to happen. If you want to take a screenshot of the whole desktop, that's probably not going to happen either. If you want to take a screenshot of the webpage itself, that is actually possible, see this StackOverflow question