方法 : アプリケーションを起動してキーストロークを送る (Visual Basic)

更新 : 2007 年 11 月

この例では、Shell 関数を使用して電卓アプリケーションを起動し、My.Computer.Keyboard.SendKeys メソッドを使用してキーストロークを送って、2 つの数値を乗算します。

使用例

Dim ProcID As Integer
' Start the Calculator application, and store the process id.
ProcID = Shell("CALC.EXE", AppWinStyle.NormalFocus)
' Activate the Calculator application.
AppActivate(ProcID)
' Send the keystrokes to the Calculator application.
My.Computer.Keyboard.SendKeys("22", True)
My.Computer.Keyboard.SendKeys("*", True)
My.Computer.Keyboard.SendKeys("44", True)
My.Computer.Keyboard.SendKeys("=", True)
' The result is 22 * 44 = 968.

このコードの例は、IntelliSense コード スニペットとしても利用できます。コード スニペット ピッカーでは、これは [Windows Forms Applications] の [Forms] にあります。詳細については、「方法 : コードにスニペットを挿入する (Visual Basic)」を参照してください。

堅牢性の高いプログラム

要求されたプロセス ID のアプリケーションが見つからない場合には、ArgumentException 例外が発生します。

セキュリティ

Shell 関数の呼び出しは、完全に信頼されている必要があります (SecurityException クラス)。

参照

参照

My.Computer.Keyboard.SendKeys メソッド

Shell 関数

AppActivate 関数