「SendKeyを使ってほかのアプリケーションにキーを送信する」
SendKeyを使ってほかのアプリケーションにキーを送信するには?
回答
SendKeyを使えば簡単にキー転送できます。
ソース
'ワードの例
Function word()
Dim ReturnValue, i
ReturnValue = Shell("winword.EXE", 1) ' wordを実行します。
AppActivate ReturnValue ' アクティブにします。
For i = 1 To 20 ' ループ カウンタを設定します。
SendKeys i & "{+}" & Chr(13), True ' wordにキー コードを転送
Next i ' I の値に 1 を加算します。
SendKeys "%{F4}", True ' Alt + F4 キーを転送して終了します。
End Function
'一定時間待つAPIの宣言
Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
'以下はかなり強引なサンプル関数です。
Function expl()
Dim ReturnValue, i
ReturnValue = Shell("C:\Program Files\Internet Explorer\iexplore.exe", 1) ' 実行します。
Sleep (2000)
AppActivate ReturnValue ' アクティブにします。
Sleep (2000)
SendKeys "建築CG" & Chr(13), True
Sleep (5000)
For i = 1 To 22
SendKeys Chr(9), True
Sleep (100)
Next i
SendKeys Chr(13), True
End Function