CodeItBetter Programming Another VB Programming Blog

How to Simulate Alt+PrintScreen to capture an image of a window in the clipboard

Posted on December 2, 2011
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
'System & API - How to Simulate Alt+PrintScreen to capture an image of a window in the clipboard
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 Const VK_MENU = &H12
Private Const VK_SNAPSHOT = &H2C
Private Const KEYEVENTF_KEYUP = &H2
 
Private Declare Function MapVirtualKey Lib "user32" Alias "MapVirtualKeyA" (ByVal wCode As Long, _
    ByVal wMapType As Long) As Long
 
Private Sub Command1_Click()
    #Const WINDOWS_VERSION = "Windows2000"
 
    Dim alt_key As Long
 
    ' Capture an image of the form in the clipboard.
    ' Press Alt.
    alt_key = MapVirtualKey(VK_MENU, 0)
    keybd_event VK_MENU, alt_key, 0, 0
    DoEvents
 
    ' Press Print Scrn.
    #If WINDOWS_VERSION = "Windows2000" Then
        keybd_event VK_SNAPSHOT, 0, 0, 0
    #Else
        keybd_event VK_SNAPSHOT, 1, 0, 0
    #End If
    DoEvents
 
    ' Release Alt.
    keybd_event VK_MENU, alt_key, KEYEVENTF_KEYUP, 0
    DoEvents
End Sub
Comments (0) Trackbacks (0)

No comments yet.


Leave a comment


 

No trackbacks yet.