1

I am using the following code to simulate a PrintScreen button press to capture the image of a Internet Explorer window. I have assigned Printscreen as a Hotkey in Greenshot tool to capture the image of the full page in one go without having to scroll.

Extern.Declare micLong, "PostMessage", "user32.dll", "PostMessageA", micHwnd, micLong, micLong, micLong

Const WM_KEYDOWN = 273
Const VK_SNAPSHOT = 44

iResult = Extern.PostMessage( Hwnd, WM_KEYDOWN, VK_SNAPSHOT, 0)

But somehow the value of iResult is always 1. Hwnd is the actual window handle of the Internet explorer window which is passed to the Postmessage function. The reason why I am using this approach is because the screenshot capturing process needs to be automated completely and should run when the system is locked as well. SendKeys does not work when system is locked and so I had to move to Post Message.

Could someone please help me out with this.

Serg
  • 2,346
  • 3
  • 29
  • 38
SteelBird
  • 85
  • 10
  • Fyi, you'll probably get a black screen when trying to take screenshots on a locked desktop under normal circumstances, but I would be interested to know if Greenshot can get around that. – Xiaofu Jul 11 '13 at 02:56
  • But somehow Greenshot does not seem to be picking up either the KeyDown or anything else. Is there something wrong with the code, am I missing something? :( – SteelBird Jul 11 '13 at 03:23
  • The problem is, this code does not work when the system is unlocked also.. – SteelBird Jul 11 '13 at 03:41
  • I can provide a method that works on an unlocked desktop using keyb_event, but it also does not work on a locked desktop since Windows ignores most keyboard input in that situation (and so is no improvement over SendKeys). – Xiaofu Jul 11 '13 at 05:19
  • Steelbird I have just answered your question at [LearnQTP forums](http://www.learnqtp.com/forums/Thread-Postmessage-function-in-QTP-for-simulating-Printscreen-key-does-not-work) Hope that helps! – Ankur Jain Jul 11 '13 at 07:30

1 Answers1

0

If the console is locked, the whole WinStation of the user session is not connected, thus the desktop does not behave in the same way as in unlocked state. It does not redraw, and more. I don´t think it is possible to ignore that. The screenshots will never show anything if the console is locked.

Ignoring that fact for a minute, I see you only send the WM_KEYDOWN message. If the user presses a key, Windows sends a WM_KEYDOWN, WM_KEYUP message for that, reflecting the depressing and releasing of the key. It might be that the target application polls for the WM_KEYUP message to trigger the screenshot. Also, it is very common for applications to ignore the WM_KEYDOWN message and react to WM_KEYUP only, among others because only on WM_KEYUP, you can query the Shift state of the keyboard, making it possible to differentiate between "A" and "Shift-A", for example.

In Capture screen on server desktop session, somebody solved a similar issue.

Community
  • 1
  • 1
TheBlastOne
  • 4,291
  • 3
  • 38
  • 72