Bagikan melalui


Cara: memulai aplikasi dan mengirimkan keystrokes (Visual Basic)

Contoh ini menggunakan Shell metode untuk memulai aplikasi Notepad lalu mencetak kalimat dengan mengirim penekanan tombol menggunakan metode My.Computer.Keyboard.SendKeys.

Contoh

Dim ProcID As Integer
' Start the Notepad application, and store the process id.
ProcID = Shell("NOTEPAD.EXE", AppWinStyle.NormalFocus)
' Activate the Notepad application.
AppActivate(ProcID)
' Send the keystrokes to the Notepad application.
My.Computer.Keyboard.SendKeys("I ", True)
My.Computer.Keyboard.SendKeys("♥", True)
My.Computer.Keyboard.SendKeys(" Visual Basic!", True)
' The sentence I ♥ Visual Basic! is printed on Notepad.

Pemrograman yang kuat

Pengecualian ArgumentException dimunculkan jika aplikasi dengan pengidentifikasi proses yang diminta tidak dapat ditemukan.

Keamanan .NET Framework

Panggilan ke Shell fungsi memerlukan kepercayaan penuh (SecurityException kelas).

Lihat juga