Ciao a tutti,
ho sostituito completamente la guida precedente, era un po' scarnina e poco funzionale, questa invece dovrebbe essere un po' meglio
Aprite il vostro visual basic .net (io ho usato il 2008 ma potete usare anche un'altra versione)
Nella form principale mettete questi controlli con questi nomi:
textbox -> txt_spam
textbox -> txt_interval (nelle proprietà impostare "enabled" su false)
trackbar-> trk_interval
checkbox-> chk_start
timer -> tim_interval
le labels con le diciture le potete chiamare come volete tanto non sono usate dal codice.
Nell'immagine di seguito potete vedere come ho disposto i controlli :
Di seguito il codice sorgente:
C++ Programming
Imports System.Runtime.InteropServices
Public Class frm_main
<DllImport("user32.dll", CharSet:=CharSet.Auto, ExactSpelling:=True)> _
Public Shared Function GetForegroundWindow() As IntPtr
End Function
<DllImport("user32.dll", CharSet:=CharSet.Auto, ExactSpelling:=True)> _
Public Shared Function GetWindowThreadProcessId(ByVal hWnd As IntPtr, ByRef processId As IntPtr) As IntPtr
End Function
Private interval As Integer = 0
Private message_array() As String
Private message_ptr As Integer = 0
Private our_prc As IntPtr = 0
Private act_prc As IntPtr = 0
Private Sub frm_main_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
GetWindowThreadProcessId(GetForegroundWindow(), our_prc)
SetTimer()
End Sub
Private Sub frm_main_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Resize
If Me.Width < chk_start.Right Then
Me.Width = chk_start.Right
End If
End Sub
Sub SetTimer()
interval = trk_interval.Value * 100
tim_interval.Interval = interval
txt_interval.Text = tim_interval.Interval / 1000
End Sub
Private Sub tim_interval_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tim_interval.Tick
GetWindowThreadProcessId(GetForegroundWindow, act_prc)
If act_prc <> our_prc Then
SendKeys.Send(message_array(message_ptr))
message_ptr += 1
If message_ptr > message_array.Length - 1 Then
message_ptr = 0
End If
End If
End Sub
Private Sub chk_start_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chk_start.CheckedChanged
If chk_start.Checked Then
FillArray()
SetTimer()
tim_interval.Enabled = True
Else
tim_interval.Enabled = False
End If
End Sub
Sub FillArray()
message_array = txt_spam.Text.Split(vbCr)
message_ptr = 0
End Sub
Private Sub trk_interval_Scroll(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles trk_interval.Scroll
SetTimer()
End Sub
End Class
Come al solito, quando avrò tempo aggiungerò un po' di commenti di spiegazione, ora sono preso
ciao
Digger