次の方法で共有


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

この例では、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.

信頼性の高いプログラミング

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

セキュリティ

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

参照

関連項目

SendKeys

Shell

AppActivate