Example Code

Programmatically Acquire a Screen Capture in LabVIEW

Code and Documents

Attachment

Overview
This example is used to Demonstrates the use of the LabVIEW to take a screen capture.

 

 
Description
Using the Call Library Function Node, LabVIEW can access and execute Windows Dynamic Link Library (DLL) Files. In this example, the Call Library Function Node used to access the user32.dll in and call the keybd_event button which allowed to simulate a key press. By simulating a press of the Print Screen button, it can then access image data stored to the clipboard via the use of the Clipboard. Get Image Invoke Node. By Bundling this data together, it can then edit and process this image in LabVIEW.

 


Requirements

  • LabVIEW 2013 (or compatible)


Steps to Implement or Execute Code

  1. Download the attached folder to your computer
  2. Open the VI "Screen Capture 2013 NIVerified.vi"
  3. Run the VI

 

Additional Information or References
VI Snippet

 Block Diagram.PNG

 **This document has been updated to meet the current required format for the NI Code Exchange.**


Alex Thomas, University of Manchester School of EEE LabVIEW Ambassador (CLAD)

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.

Comments
Pete.Dunc
Active Participant
Active Participant
on

This is cool - could you use the same DLL to capture multi-key shortcuts?  Also, when is the key 'released'?

I'm thinking Alt-PrtScn to take a screen cap of the current Window.


Regards,

Peter D

parsani
Member
Member
on

Hi Alex,

this is a very good example the exact thing that I need to do, but whenever I run the program it does nothing, jut runs for a second and closes labview. I am pretty new in labview and don't know technicals but it seems that there's no error message or anything just quits labview. I made sure I have DLL file in the same directory and I also tried building an executable version of this program but even the EXE file just runs for a second doing nothing then stops.

Would you please tell me how to make it work thanks

Alex.T
Active Participant
Active Participant
on

Have you made any changes to the DLL call? I've noticed that this happens when the Call Library Function Node is configured in an improper manner; it's mainly an issue due to the calling convention; it should be set to stdcall (WINAPI).

I'd also recommend that you check out this KnowledgeBase Article.

What OS are you currently using? This was made on Windows 7, however there are some incompatibilities with the XP DLL. Have you reconfigured the Call Library Function Node to point at the downloaded user32 DLL?


Alex Thomas, University of Manchester School of EEE LabVIEW Ambassador (CLAD)

parsani
Member
Member
on

Hi Alex, thanks for your quick reply. Actually I did not touch the code just opened your program to study it.

- I am using Windows7 32bit

- Running the code does not crash labview but it just does nothing and runs for a sec and stops.

- All I need is  to have a VI with a button to save a JPG or PNG out of screen ( If it can automatically name the files would be great)

Can you please help me out? I'm really confused and can't find anything useful

Alex.T
Active Participant
Active Participant
on

That sounds like it might be working!

On the Front Panel, right click on the Screenshot Data cluster and select Data Operations » Reinitialise to Default. Then run the VI. If you can see that the Image, Mask and Colors are no longer greyed out and now have data in them, then the VI successfully executed. You could also try taking a print screen on your computer with a particular window open, paste the image somewhere, then run the VI with the Front Panel open. If the images have changed, then that should show the DLL is being called successfully.

This example only creates data which is to be read in by LabVIEW's 2D Picture functions; therefore a small amount of processing will be required to convert it into a viewable picture. Try dropping the Draw Flattened Pixmap.vi, found in the Graphics and Sound palette and wiring the Screenshot Data in. The output of the Draw Flattened Pixmap will be the acquired screenshot image, so you could use a 2D Picture indicator to view it.


Alex Thomas, University of Manchester School of EEE LabVIEW Ambassador (CLAD)

parsani
Member
Member
on

Hi alex,

I just wrote a code to capture screen it's not quite the same as yours, and I also made a Auto-Naming system based on the date and time. Everything works fine but I still have a slight issue, after saving file It doesn't have any extention such as JPG or BMP (I guess because of the autonaming strategy it just overwrites the whole name and extention is left out). Would you please give me your email so I can send you my VI so you can have a look? thanks very much

my email: ali.farsani@trinitytechinc.ca

Cheers

Alex.T
Active Participant
Active Participant
on

For help with LabVIEW Programming, be sure to check out the NI Forums; the guys over there are incredibly helpful!


Alex Thomas, University of Manchester School of EEE LabVIEW Ambassador (CLAD)

fredcm1
Member
Member
on

Hi Alex,

Did you already tested this vi in a executable? I made a executable but it did not work.

opejumeys
Member
Member
on

For the Alt+Print Screen question, you just need to have a keyboard event for the button push and the button release (third parameter: 0 --> press, 2 --> release).

An important note is that the enum in the original VI is incorrect.  If you select ALT, the enum is actually set to the CTRL key. Also the inputs are the Unsigned instead of signed data types (but that shouldn't affect the overall program).

It won't let me attach code to this comment, so I will just add a screen shot of the code that will actually work for Alt+print screen.

alt_print screen.PNG

As for the executable, I have no problem running this in an executable using LabVIEW 2012.

drimage
Member
Member
on

i like using twain technology to capture a screen image vb, so i found it is pretty cool to be able to edit and process images in the software.

colinzhang
Member
Member
on

Hi Alex,

This code is not working after building .exe application on LV2010.  VI is working fine. What's the problem?  Please refer to this link --my post on NI Forums.

Colin Zhang
------------------
LV7.1/8.2/8.2.1/8.5/8.6/9.0/2010/2013/2016/2020; testing system development
Please Mark the solution as accepted if your problem is solved and donate kudoes


Home--colinzhang.net: My Blog

iTestGroup: One-step test solution provider!
ONTAP.LTD : PCBA test solution provider
WireFighter
Member
Member
on
For me the VI will only work when I insert an 50ms delay between call library function
node and the invoke node. Otherwise I get back only the last contents of the Clipboard (Windows 7).

grubworm
Member
Member
on

Hey cool ie.  Is than any way to just grab the pc video memory right off the bus?  I want to transfer the image (portion) on the monitor over udp to another cpu.  I just love this stuff!

Thanks,

Andy B

margaret90
Member
Member
on

Hi Alex,

Do you know how to improve the quality of the image which we capture? Since I need very high quality of my image and I can only get low-quality image when I capture the screenshot.

Thanks,

Jiayi

Ajayvignesh_MV
Active Participant
Active Participant
on

Thanks dude.  This has helped me to capture the screenshot.

Wez
Member
Member
on

worked right out of the box for me on my surface pro 3 running windows 10. thanks a lot.