【WSH】VBScriptでPrintscreen・Alt+Printscreenしてみた
打鍵テスト自動化スクリプトをなんとなく作成していた時のメモ。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | |
参考URL
関連する公式情報はこのあたり
- keybd_event関数 http://msdn.microsoft.com/ja-jp/library/cc364822.aspx
- CALL 関数と REGISTER 関数の使い方 http://office.microsoft.com/ja-jp/excel-help/HP010062480.aspx
関連情報の検索キーワード
- VBScript DLL呼び出し
どうでもいいかもしれないけども、カテゴリ名をWSHにするかVBScriptにするかすごく迷った。