25 diciembre 2012

VB.NET - Apps - Código - AutoTecleo - (2005, 2008)

Public Class frm_Main
    'craneodelrey@msn.com

    Public Send_Keys As Boolean 'Inicia o Detiene el AutoTecleo

    '<<><<>----<<><<>----<<><<>----<<><<>----<<><<>----<<><<>----<<><<>----<<><<>----<<><<>----<<><<>----
    'Declaración de la función GetAsyncKeyState que se usa para leer la pulsación de las teclas F7 y F8
    '<<><<>----<<><<>----<<><<>----<<><<>----<<><<>----<<><<>----<<><<>----<<><<>----<<><<>----<<><<>----
    <System.Runtime.InteropServices.DllImport("user32.dll", ExactSpelling:=True, CharSet:=System.Runtime.InteropServices.CharSet.Auto)> _
    Public Shared Function GetAsyncKeyState(ByVal vkey As Integer) As Short
    End Function
    '----<>><>>----<>><>>----<>><>>----<>><>>----<>><>>----<>><>>----<>><>>----<>><>>----<>><>>----<>><>>


    Private Sub frm_Main_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.Send_Keys = False
        Me.TransparencyKey = Color.LightGray
    End Sub

    '<<><<>----<<><<>----<<><<>----<<><<>----<<><<>----<<><<>----<<><<>----<<><<>----<<><<>----<<><<>----
    'Iniciar el AutoTecleo estableciendo Send_Keys = True, luego cambia a un tiempo de espera largo para
    'no interferir durante el proceso de AutoTecleo
    '<<><<>----<<><<>----<<><<>----<<><<>----<<><<>----<<><<>----<<><<>----<<><<>----<<><<>----<<><<>----
    Private Sub tmr_Timer_1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmr_Timer_1.Tick
        Dim Key_State As Integer
        Me.tmr_Timer_1.Interval = 10
        Key_State = GetAsyncKeyState(Keys.F7)

        If Key_State < 0 Then
            Me.Send_Keys = True
            Me.tmr_Timer_1.Interval = (60) * (60) * (1000)
            Me.AutoSendKeys()
        End If
    End Sub
    '----<>><>>----<>><>>----<>><>>----<>><>>----<>><>>----<>><>>----<>><>>----<>><>>----<>><>>----<>><>>


    '<<><<>----<<><<>----<<><<>----<<><<>----<<><<>----<<><<>----<<><<>----<<><<>----<<><<>----<<><<>----
    'Tratar de finalizar e interrumpir el proceso de AutoTecleo estableciendo Send_Keys = False
    '<<><<>----<<><<>----<<><<>----<<><<>----<<><<>----<<><<>----<<><<>----<<><<>----<<><<>----<<><<>----
    Private Sub tmr_Timer_2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmr_Timer_2.Tick
        Dim Key_State As Integer
        Key_State = GetAsyncKeyState(Keys.F8)
        If Key_State < 0 Then
            Me.Send_Keys = False
        End If
    End Sub
    '----<>><>>----<>><>>----<>><>>----<>><>>----<>><>>----<>><>>----<>><>>----<>><>>----<>><>>----<>><>>

    '<<><<>----<<><<>----<<><<>----<<><<>----<<><<>----<<><<>----<<><<>----<<><<>----<<><<>----<<><<>----
    'Función que realiza el AutoTecleo
    '<<><<>----<<><<>----<<><<>----<<><<>----<<><<>----<<><<>----<<><<>----<<><<>----<<><<>----<<><<>----
    Private Sub AutoSendKeys()
        Dim Times, Lines, Count, i As Int32
        Dim Interval As Decimal
        Dim Errors As String
        Dim MessageArray() As String

        Times = Convert.ToInt32(Me.nud_Times.Value.ToString())
        Interval = Convert.ToDecimal(Me.nud_Interval.Value.ToString())
        Lines = Me.txt_Message.Lines.Length
        Count = 0
        Errors = ""

        If (Times <= 0) Then
            Errors = Errors + "Times > 0" + Chr(13)
        End If

        If (Interval <= 0) Then
            Errors = Errors + "Interval > 0" + Chr(13)
        End If

        If (Lines <= 0) Then
            Errors = Errors + "There aren't Text to Write" + Chr(13)
        End If

        If (Errors = "") Then
            ReDim MessageArray(Lines)
            For i = 0 To Lines - 1
                MessageArray(i) = Me.txt_Message.Lines(i).ToString()
            Next

            While (Me.Send_Keys = True And Count < Times)
                For i = 0 To Lines - 1
                    If (Me.Send_Keys = True) Then
                        SendKeys.SendWait(MessageArray(i))
                        If (i < Lines - 1) Then
                            SendKeys.SendWait("{ENTER}")
                        End If
                        System.Threading.Thread.Sleep(Interval * 1000)
                    End If
                Next
                Count = Count + 1
            End While
            Me.Send_Keys = False
        Else
            MessageBox.Show(Errors)
        End If
        Me.tmr_Timer_1.Interval = 10
    End Sub
    '----<>><>>----<>><>>----<>><>>----<>><>>----<>><>>----<>><>>----<>><>>----<>><>>----<>><>>----<>><>>
End Class

No hay comentarios: