Limiti dei batch puri
Un file .bat esegue comandi DOS/console. Non può cliccare GUI né premere tasti in finestre Windows senza strumenti esterni.
Soluzione: Windows Script Host (WSH) + SendKeys
- Crea un file
tasti.vbs(VBScript):
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "notepad.exe"
WScript.Sleep 1000
WshShell.SendKeys "Hello from batch!"
WshShell.SendKeys "{ENTER}"
- Nel batch
mio.batrichiama:
@echo off
cscript //nologo tasti.vbs
Codici SendKeys principali
| Tasto | Codice |
|---|---|
| Alt | % |
| Ctrl | ^ |
| Shift | + |
| Enter | {ENTER} |
| Tab | {TAB} |
| F1‑F12 | {F1}…{F12} |
| Freccia su | {UP} |
| Freccia giù | {DOWN} |
| Esc | {ESC} |
Esempio: aprire Word e creare nuovo documento
Set sh = CreateObject("WScript.Shell")
sh.Run "winword.exe"
WScript.Sleep 3000
sh.SendKeys "^n" ' Ctrl+N = nuovo documento
Alternative più potenti
- AutoHotkey (script .ahk) – hotkey, GUI automation, DLL calls.
- PowerShell +
Add-Type -AssemblyName System.Windows.Forms→[System.Windows.Forms.SendKeys]::SendWait(). - Python +
pyautogui/pynput.
Attenzione
SendKeys è fragile: dipende da focus finestra, tempistiche, layout tastiera. Usa per task semplici; per automazione robusta preferisci AutoHotkey o Python.
- Ripristino configurazione di sistema e Reset PC Dell (Windows XP/Vista/7)
- Trasferire audiolibri Audible su Kindle
Windows 11
- Eliminare il rumore statico in Ableton Live 8 con l'effetto Gate
- Sfocare sfondo in Adobe Lightroom (Pennello regolazione / Maschera AI)
- Ascoltare XM Radio (SiriusXM) su iPad
- Come inizializzare NVM (memoria non volatile) su stampanti/multifunzione Xerox
- Guida completa alla configurazione dell'app SwannView su iPhone
- Come guadagnare scrivendo lettere online
- iPhone 6 Plus: ne vale la pena? (Analisi storica 2014)
- Giocare a vecchi giochi DOS (Doom, Quake, Duke Nukem 3D) su PSP con DOSBox