Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27511

VS 2010 How do I implement this code into mine?

$
0
0
This is my code:
Code:

Imports System.Runtime.InteropServices

Public Class Form1
    Public Const WM_HOTKEY As Integer = &H312

    <DllImport("User32.dll")> _
    Public Shared Function RegisterHotKey(ByVal hwnd As IntPtr, _
                        ByVal id As Integer, ByVal fsModifiers As Integer, _
                        ByVal vk As Integer) As Integer
    End Function

    <DllImport("User32.dll")> _
    Public Shared Function UnregisterHotKey(ByVal hwnd As IntPtr, _
                        ByVal id As Integer) As Integer
    End Function

    Private Sub Form1_Load(ByVal sender As System.Object, _
                        ByVal e As System.EventArgs) Handles MyBase.Load
        RegisterHotKey(Me.Handle, 100, Nothing, Keys.F10)
    End Sub

Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
        If m.Msg = WM_HOTKEY Then
            Select Case m.WParam.ToInt32
                Case 100
                    If Not Timer1.Enabled Then
                        Timer1.Start()
                        Me.WindowState = 1
                    ElseIf Timer1.Enabled Then
                        Timer1.Stop()
                        Me.WindowState = vbNormal
                    End If
            End Select
        End If
        MyBase.WndProc(m)
    End Sub

    Private Sub Form1_FormClosing(ByVal sender As System.Object, _
                        ByVal e As System.Windows.Forms.FormClosingEventArgs) _
                        Handles MyBase.FormClosing
        UnregisterHotKey(Me.Handle, 100)
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        ListBox1.Items.Add(TextBox1.Text)
    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        For Each Item In ListBox1.Items
            SendKeys.Send(Item)
            SendKeys.Send("{Enter}")
            Threading.Thread.Sleep(TextBox2.Text)
        Next
    End Sub
End Class


This is the code I am trying to implement:

Code:

Private WithEvents macroTimer As New Timer
 
Private WithEvents microTimer As New Timer
 
Private itemIndex As Integer = 0
 
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    macroTimer.Interval = 60 * 1000
    macroTimer.Start()
 
    microTimer.Interval = 1000
End Sub
 
Private Sub macroTimer_Tick(sender As Object, e As EventArgs) Handles macroTimer.Tick
    microTimer.Start()
 
    SendCurrentItem()
End Sub
 
Private Sub microTimer_Tick(sender As Object, e As EventArgs) Handles microTimer.Tick
    SendCurrentItem()
 
    If itemIndex = ListBox1.Items.Count Then
        microTimer.Stop()
        itemIndex = 0
    End If
End Sub
 
Private Sub SendCurrentItem()
    Dim itemText = ListBox1.GetItemText(ListBox1.Items(itemIndex))
 
    SendKeys.Send(itemText)
    SendKeys.Send("{Enter}")
 
    itemIndex += 1
End Sub


This thread is meant for jmcilhinney since I can't send this to him via PM since it contains too many characters.

Viewing all articles
Browse latest Browse all 27511

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>