Skip to content

Instantly share code, notes, and snippets.

@kunst1080
Last active December 14, 2015 14:19
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save kunst1080/5099908 to your computer and use it in GitHub Desktop.
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