Så här startar du ett program och skickar det tangenttryckningar (Visual Basic)

I det Shell här exemplet används metoden för att starta Anteckningar-programmet och skriver sedan ut en mening genom att skicka tangenttryckningar med hjälp av metoden My.Computer.Keyboard.SendKeys .

Exempel

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.

Robust programmering

Ett ArgumentException undantag utlöses om ett program med den begärda processidentifieraren inte kan hittas.

.NET Framework-säkerhet

Anropet till funktionen Shell kräver fullständigt förtroende (SecurityException-klass).

Se även