2

I wish to send the "Print Screen"-key to an application. Preferably using Powershell.

I do not wish to capture the screen!

I tried using the SendKeys() method like this

$shell = New-Object -Com wscript.shell
$shell.SendKeys('{PRTSC}')

but this MSDN article states, that "Print Screen" cannot be sent to an application using the SendKeys function and even after trying it did not work.

Is there a way to send this key to an application?

briantist
  • 45,546
  • 6
  • 82
  • 127
Daniel
  • 458
  • 5
  • 16
  • I see this question was marked as a duplicate of a question asking how to capture the screen but as I said that is exactly what I do not want to do. "I do not wish to capture the screen!" – Daniel May 29 '18 at 17:42
  • So waht do you wish to capture. If you have an application open then press the print screen button, a screen capture happens unless something else intercepts the keypress. What is your ultimate goal? – EBGreen May 29 '18 at 17:42
  • @EBGreen The application in question is blocking remote viewing (through AWS AppStream 2.0) but allows to disable this feature when pressing the "Print Screen" key, then a dialog opens and when the user clicks "OK"/"Yes" this function is disabled during the current session. As I do not wish to tell every user to hit "Print Screen", press "Left arrow" and then press "Enter" I would like to write a script which starts the application and does that automatically. – Daniel May 29 '18 at 17:45
  • I would add this as an answer but I can't so I'll do it here: A software called "AutoHotKey" has the ability to compile scripts written for it to an executable which can in turn be called by PowerShell and therefore satisfies my requirement of an automatic way to circumvent the beforementioned "security" feature (or the requirement to automatically send the "Print Screen" keystroke to an application), preferably using PowerShell. – Daniel May 29 '18 at 20:16
  • 2
    @Daniel I've reopened it because it's an interesting question, and it's hard to find an answer for this elsewhere that doesn't involve a screenshot. But I'm hoping we get a better answer than "use AutoHotKey" as at that point it's not really about programming. AHK must be implementing it somehow. – briantist May 30 '18 at 04:10
  • @Daniel Did you try to put AWS AppStream 2.0 in [foreground with Powershell](http://community.idera.com/powershell/powertips/b/tips/posts/bringing-window-in-the-foreground) before sending keys? That's how I made connections to remote registries as it's not possible by sending a parameter to regedit.exe – Manu May 30 '18 at 09:19
  • @Manu Yes I did. Other keystrokes were sent to the application, but not the "Print Screen"-key. – Daniel May 30 '18 at 19:19
  • @briantist I suppose because AHK implements globalhook too. In that case it maybe alters keycode meaning in lower level. – anefeletos Dec 08 '21 at 21:39

0 Answers0