mjsummers
mjsummers

Reputation: 43

multiple hotkey commands in a autohotkey script

I'm trying to write a script that will do one of the following based on hotkey commands using one autohotkey script: a) open a specific (1 out of 10) vnc connection accross a network, b) open 5 (5 out of 10) separate vnc connections accross a network, and c) open all 10 vnc connections accross a network. Each iteration of the script opens a separate connection to the host machine in question. I can get item "c" to work on command, however items (a) and (b) will open more connections than I need, and Im trying to end each hotkey with something like end or exit at the end of its respective script. I have listed the code for items (a) and (b) below as those are the ones that this applies to:

Item (a) and part of Item (b) [for Item (b) this is repeated x times]

^!c::
   {
    Run, vnc-E4_6_3-x86_win32_viewer.exe, C:\Program Files (x86)\RealVNC\VNC4 Viewer
     WinWaitActive, VNC Viewer
      {
       Send Frankenstien-SubSystem-1
       Send {enter}
      }
     WinWaitActive, Authentication Credentials
      {
       Send {Shift Down}
       Send {Tab}
       Send {Shift Up}
       Send <username>
       Send {Tab}
       Send <password>
       Send {enter}
      }
     Sleep 2000 [Only used for items (b) and (c) ;<== End here for Item (a) only
    }

For Item (b)

#a::
   {
    Run, vnc-E4_6_3-x86_win32_viewer.exe, C:\Program Files (x86)\RealVNC\VNC4 Viewer
     WinWaitActive, VNC Viewer
      {
       Send Frankenstien-SubSystem-1
       Send {enter}
      }
     WinWaitActive, Authentication Credentials
      {
       Send {Shift Down}
       Send {Tab}
       Send {Shift Up}
       Send <username>
       Send {Tab}
       Send <password>
       Send {enter}
      }
     Sleep 2000 [Only used for items (b) and (c)
    Run, vnc-E4_6_3-x86_win32_viewer.exe, C:\Program Files (x86)\RealVNC\VNC4 Viewer
     WinWaitActive, VNC Viewer
      {
       Send Frankenstien-SubSystem-2
       Send {enter}
      }
     WinWaitActive, Authentication Credentials
      {
       Send {Shift Down}
       Send {Tab}
       Send {Shift Up}
       Send <username>
       Send {Tab}
       Send <password>
       Send {enter}
      }
     Sleep 2000 [Only used for items (b) and (c)
    Run, vnc-E4_6_3-x86_win32_viewer.exe, C:\Program Files (x86)\RealVNC\VNC4 Viewer
     WinWaitActive, VNC Viewer
      {
       Send Frankenstien-SubSystem-3
       Send {enter}
      }
     WinWaitActive, Authentication Credentials
      {
       Send {Shift Down}
       Send {Tab}
       Send {Shift Up}
       Send <username>
       Send {Tab}
       Send <password>
       Send {enter}
      }
     Sleep 2000 [Only used for items (b) and (c)
    Run, vnc-E4_6_3-x86_win32_viewer.exe, C:\Program Files (x86)\RealVNC\VNC4 Viewer
     WinWaitActive, VNC Viewer
      {
       Send Frankenstien-SubSystem-4
       Send {enter}
      }
     WinWaitActive, Authentication Credentials
      {
       Send {Shift Down}
       Send {Tab}
       Send {Shift Up}
       Send <username>
       Send {Tab}
       Send <password>
       Send {enter}
      }
     Sleep 2000 [Only used for items (b) and (c)
    Run, vnc-E4_6_3-x86_win32_viewer.exe, C:\Program Files (x86)\RealVNC\VNC4 Viewer
     WinWaitActive, VNC Viewer
      {
       Send Frankenstien-SubSystem-5
       Send {enter}
      }
     WinWaitActive, Authentication Credentials
      {
       Send {Shift Down}
       Send {Tab}
       Send {Shift Up}
       Send <username>
       Send {Tab}
       Send <password>
       Send {enter}
      }
      ;END Here; <== Item (b) twice
     }

How can i force the hotkey to end when it finishes a given task, but keeps going given what I have provided?

Upvotes: 3

Views: 5518

Answers (1)

Elliot DeNolf
Elliot DeNolf

Reputation: 2999

You're looking for the Return command to stop the execution of your hotkeys. See the piece of code below. I've created a function which you can use to call a specific machine without so much code repetition. This way you will get the specific machines you desire.

#a::VNC("Frankenstien-SubSystem-1", "myuser", "mypass")

#b::
    VNC("Frankenstien-SubSystem-1", "myuser", "mypass")
    VNC("Frankenstien-SubSystem-2", "myuser", "mypass")
    VNC("Frankenstien-SubSystem-3", "myuser", "mypass")
    VNC("Frankenstien-SubSystem-4", "myuser", "mypass")
    VNC("Frankenstien-SubSystem-5", "myuser", "mypass")
    Return

#c::
    VNC("Frankenstien-SubSystem-1", "myuser", "mypass")
    VNC("Frankenstien-SubSystem-2", "myuser", "mypass")
    VNC("Frankenstien-SubSystem-3", "myuser", "mypass")
    VNC("Frankenstien-SubSystem-4", "myuser", "mypass")
    VNC("Frankenstien-SubSystem-5", "myuser", "mypass")
    ; ... and so on
    Return


VNC(machine, user, pw)
{
    Run, vnc-E4_6_3-x86_win32_viewer.exe, C:\Program Files (x86)\RealVNC\VNC4 Viewer
    WinWaitActive, VNC Viewer
    {
        Send % machine
        Send {enter}
    }
    WinWaitActive, Authentication Credentials
    {
        Send {Shift Down}
        Send {Tab}
        Send {Shift Up}
        Send % user
        Send {Tab}
        Send % pw
        Send {enter}
    }
    Sleep 2000
    }
}

Upvotes: 5

Related Questions