How can I simulate a PrintScrn key to save a picture of screen to a file?
Printable View
How can I simulate a PrintScrn key to save a picture of screen to a file?
Code:Option Explicit
Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
Private Sub Command1_Click()
'1 is the screen. Replace it with 0 and you'll get the form
keybd_event vbKeySnapshot, 1, 0&, 0&
'update the clipboard before doing something else
DoEvents
'copy clipboard to the picturebox (vbCFBitmap = 2)
Picture1 = Clipboard.GetData(vbCFBitmap)
Clipboard.Clear
Clipboard.SetData Picture1.Picture
End Sub
Sorry! Use this line to save to a file. I only know how to save it as a BMP. If you want JPEG, search through this site and I think someone knows how to do it.
Code:' PURPOSE: Save the clipboard picture
SavePicture Clipboard.GetData(vbCFBitmap), "C:\Test.bmp"