Procedura: avviare un'applicazione e inviarle sequenze di tasti (Visual Basic)

Questo esempio usa il metodo Shell per avviare l'applicazione Blocco note e quindi stampa una frase inviando sequenze di tasti usando il metodo My.Computer.Keyboard.SendKeys.

Esempio

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.

Programmazione efficiente

Se non viene rilevata un'applicazione con l'identificatore di processo richiesto, viene generata un'eccezione ArgumentException.

Sicurezza di .NET Framework

La chiamata alla funzione Shell richiede l'attendibilità totale (classe SecurityException).

Vedi anche