codice:
Option Explicit
Rem creare il CommandButton "command1"
Rem creare la ListBox "list1"
Rem creare il Timer "timer1"
Private Declare Sub keybd_event Lib "user32.dll" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
Private Sub Command1_Click()
Rem INVIA DATI ALLA TASTIERA
Const KEYEVENTF_EXTENDEDKEY = &H1
Const KEYEVENTF_KEYUP = &H2
Command1.Caption = "interrompi"
Dim ReturnValue, I
ReturnValue = Shell("notepad.exe", 1) ' Esegue il note.
keybd_event Asc(" "), 0, 1, 0 ' Invia sequenze di tasti
keybd_event Asc("A"), 0, 1, 0 ' Invia sequenze di tasti
keybd_event Asc("T"), 0, 0, 0 ' Invia sequenze di tasti
keybd_event Asc("T"), 0, 2, 0 ' Invia sequenze di tasti
keybd_event Asc("T"), 0, 0, 0 ' Invia sequenze di tasti
keybd_event Asc("T"), 0, 2, 0 ' Invia sequenze di tasti
keybd_event Asc("E"), 0, 1, 0 ' Invia sequenze di tasti
keybd_event Asc("N"), 0, 1, 0 ' Invia sequenze di tasti
keybd_event Asc("D"), 0, 1, 0 ' Invia sequenze di tasti
keybd_event Asc("I"), 0, 1, 0 ' Invia sequenze di tasti
keybd_event Asc(" "), 0, 1, 0 ' Invia sequenze di tasti
keybd_event Asc("I"), 0, 1, 0 ' Invia sequenze di tasti
keybd_event Asc("L"), 0, 1, 0 ' Invia sequenze di tasti
keybd_event Asc(" "), 0, 0, 0 ' Invia sequenze di tasti
keybd_event Asc("1"), 0, 0, 0 ' Invia sequenze di tasti
keybd_event Asc("1"), 0, 2, 0 ' Invia sequenze di tasti
keybd_event Asc("0"), 0, 0, 0 ' Invia sequenze di tasti
keybd_event Asc("0"), 0, 2, 0 ' Invia sequenze di tasti
keybd_event Asc(" "), 0, 0, 0 ' Invia sequenze di tasti
keybd_event Asc(" "), 0, 2, 0 ' Invia sequenze di tasti
keybd_event Asc(" "), 0, 0, 0 ' Invia sequenze di tasti
keybd_event Asc(" "), 0, 2, 0 ' Invia sequenze di tasti
For I = 0 To 9 ' Imposta il ciclo di conteggio.
TEMPOSEC (0.3)
keybd_event Asc(I), 0, 0, 0 ' Invia sequenze di tasti
keybd_event Asc(I), 0, 2, 0 ' Invia sequenze di tasti
keybd_event Asc(" "), 0, 1, 0 ' Invia sequenze di tasti
Next I ' ciascun valore di I.
keybd_event Asc(" "), 0, 0, 0 ' Invia sequenze di tasti
keybd_event Asc(" "), 0, 2, 0 ' Invia sequenze di tasti
keybd_event Asc("F"), 0, 0, 0 ' Invia sequenze di tasti
keybd_event Asc("F"), 0, 2, 0 ' Invia sequenze di tasti
keybd_event Asc("I"), 0, 0, 0 ' Invia sequenze di tasti
keybd_event Asc("I"), 0, 2, 0 ' Invia sequenze di tasti
keybd_event Asc("N"), 0, 0, 0 ' Invia sequenze di tasti
keybd_event Asc("N"), 0, 2, 0 ' Invia sequenze di tasti
keybd_event Asc("I"), 0, 0, 0 ' Invia sequenze di tasti
keybd_event Asc("I"), 0, 2, 0 ' Invia sequenze di tasti
keybd_event Asc("T"), 0, 0, 0 ' Invia sequenze di tasti
keybd_event Asc("T"), 0, 2, 0 ' Invia sequenze di tasti
keybd_event Asc("O"), 0, 0, 0 ' Invia sequenze di tasti
keybd_event Asc("O"), 0, 2, 0 ' Invia sequenze di tasti
keybd_event Asc(" "), 0, 0, 0 ' Invia sequenze di tasti
keybd_event Asc(" "), 0, 2, 0 ' Invia sequenze di tasti
TEMPOSEC (1)
keybd_event vbKeyMenu, 0, 0, 0 ' Invia sequenze di tasti
keybd_event vbKeyF4, 0, 0, 0 ' Invia sequenze di tasti
keybd_event vbKeyF4, 0, 2, 0 ' Invia sequenze di tasti
keybd_event vbKeyMenu, 0, 2, 0 ' Invia sequenze di tasti
TEMPOSEC (1)
keybd_event Asc("N"), 0, 0, 0 ' Invia sequenze di tasti
keybd_event Asc("N"), 0, 2, 0 ' Invia sequenze di tasti
Command1.Caption = "completato"
Rem chiudi operazione
TEMPOSEC (1)
End
End Sub
Private Sub List1_Click()
Rem RICEVI DATI DALLA TASTIERA
Rem avvia o termina la ricerca dei dati
Timer1.Interval = 250
Timer1.Enabled = Not Timer1.Enabled
If Timer1.Enabled = True Then
Rem operazione all'inizio dell'attesa
Beep
List1.Clear
List1.AddItem "avviato", 0
List1.AddItem "", 0
Else
Rem operazione termine dell'attesa
Beep
List1.AddItem "» FINE «", 0
End If
End Sub
Private Sub Timer1_Timer() ' {█ area importante █}
Rem RICERCA DATI DALLA TASTIERA
Dim UN, DU, TR, QU
keybd_event UN, DU, TR, QU
List1.AddItem UN + " ; " + DU + " ; " + TR + " ; " + QU + " ; "
End Sub {█ area importante █}
Private Sub TEMPOSEC(MaXSeC As Double)
'temporizzazione calcolo
Dim PauseTime, Start, Finish, TotalTime
PauseTime = MaXSeC ' Imposta la durata.
Start = Timer ' Imposta l'ora di inizio.
Do While Timer < Start + PauseTime
DoEvents ' Passa il controllo ad altri processi.
Loop
Finish = Timer ' Imposta l'ora di fine della pausa.
TotalTime = Finish - Start ' Calcola il tempo totale.
Form1.Caption = Form1.Caption + " -> " + (CurDir("")) 'restituzione directory iniziale
End Sub
Grazie ancora per la pazienza