开发者

SendKeys and Taking Photos of Screen

I made this VB.NET code to take a picture of my entire screen, but instead it only takes a photo of the focused area. Why is this?

  Public Function SaveScreen(ByVal theFile As String) As Boolean

            Try
                SendKeys.Send("{PRTSC}")
                Application.DoEvents()

                Dim data As IDataObject = Clipboard.GetDataObject()

                If data.GetDataPresent(GetType(System.Drawing.Bitmap)) Then
                    Dim bmp As Bitmap = CType(data.GetData(GetTy开发者_运维知识库pe(System.Drawing.Bitmap)), Bitmap)
                    bmp.Save(theFile, Imaging.ImageFormat.Png)
                End If
                Clipboard.SetDataObject(0)      'save memory by removing the image from the clipboard
                Return True
            Catch ex As Exception
                Return False
            End Try

        End Function


instead SendKeys, you can try the API-function keybd_event

Private Declare Sub keybd_event Lib "user32.dll" (ByVal bVk As Byte, _
ByVal bScan As Byte, ByVal dwFlags As Integer, ByVal dwExtraInfo As Integer)

Private Const kbdDown = 0
Private Const kbdUp = 2



Private Sub SendKey(ByVal Key As Byte)
    Call keybd_event(Key, 0, kbdDown, 0)
    Call keybd_event(Key, 0, kbdUp, 0)

End Sub

The Key-Code of Print-Key is 42 (0x2A)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜