Link to home
Start Free TrialLog in
Avatar of jdoheny
jdoheny

asked on

Alt Tab multiple times in VB2005 with a program...

So I've been working on this for awhile, but what I need to happen is I have these applications open ( Internet Explorer, Outlook, VBA, VB, Calculator...) and I want my program to just tab through them all. So if I have 4 programs open, it should tab 3 times, and then tab 3 times repeatedly and it would go through each of the tabs and I was putting this in a loop that basically never ends because I want to do it until the user shuts it down.

I've tried so many pieces of code and none of them have worked, including mine which I think doesn't work because it only recognizes alt tabbing once.

Any help would be so appreciated. :(
Public Class Form1
 
    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
 
    End Sub
    Sub Delay(ByVal dblSecs As Double)
        Const OneSec As Double = 1.0# / (1440.0# * 60.0#)
        Dim dblWaitTil As Date
 
        dblWaitTil = Now.AddSeconds(OneSec).AddSeconds(dblSecs)
        Do Until Now > dblWaitTil
            Application.DoEvents() ' Allow windows messages to be processed
        Loop
 
    End Sub
 
    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
 
 
        Dim i As Integer
        ' Dim j As Integer
        i = 0
 
        Dim windowszzz As Integer
        windowszzz = 1
 
        For i = 0 To windowszzz
            'Delay(5)
            ' For j = 0 To i
            SendKeys.Send("%{TAB}")
            Delay(5)
            SendKeys.Send("%{TAB}{TAB}")
            Delay(5)
            SendKeys.Send("%{TAB}{TAB}{TAB}")
            Delay(5)
            SendKeys.Send("%{TAB}{TAB}{TAB}")
            Delay(5)
            SendKeys.Send("%{TAB}{TAB}{TAB}")
            'Next
        Next
 
    End Sub
End Class

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jdoheny
jdoheny

ASKER

I'm a little distressed that a number after the word solved my problem that I spent so long on, but so happy! Thank you so much for all your help :)!
Glad that worked.

Looking back at my answer, though, #1 should have "%" instead of "@", and read:

    (1) Put "%" in front of all of them:

        SendKeys.Send("%{TAB}%{TAB}%{TAB}")

Guess I needed more coffee yesterday...   ;)