Skip to content

Instantly share code, notes, and snippets.

@kunst1080 kunst1080/PrintScreen.vbs
Last active Dec 14, 2015

Embed
What would you like to do?
VBScriptから Printscreen・Alt+Printscreen するサンプル
Set SHELL = WScript.CreateObject("WScript.Shell")
Set Excel = WScript.CreateObject("Excel.Application")
'KEY CODE
Const VK_SNAPSHOT = &H2C
Const VK_MENU = &H12
Sub PrintScreen
'PrintScreen On
Call API_keybd_event(VK_SNAPSHOT,0,1,0)
'PrintScreen Off
Call API_keybd_event(VK_SNAPSHOT,0,3,0)
End Sub
Sub AltPrintScreen(window_name)
SHELL.AppActivate window_name
'Alt On
Call API_keybd_event(VK_MENU,0,1,0)
PrintScreen
'Alt Off
Call API_keybd_event(VK_MENU,0,3,0)
End Sub
Sub API_keybd_event(bVk, bScan, dwFlags, dwExtraInfo)
Dim strFunction
Const API_STRING = "CALL(""user32"",""keybd_event"",""JJJJJ"", $1, $2, $3, $4)"
strFunction = Replace(Replace(Replace(Replace(API_STRING, "$1", bVk), "$2", bScan), "$3", dwFlags), "$4", dwExtraInfo)
Call Excel.ExecuteExcel4Macro(strFunction)
End Sub
'***************************************
'Simplae Test
'***************************************
'PrintScreen
AltPrintScreen "Garden"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.