Jump to content

Creating hotkey that launches a program and performs a loop and closes it if used again


Recommended Posts

Hey all! This is probably the most simple request in the forum that will make most of the experienced users go "DUH!"

Being a total noobie I'm still trying to figure things out. Basically wanted to create a hotkey that will launch a program, then run an infinite loop within the program until the hotkey is pressed again.

So far I've made this...and while it launches notepad, it won't enter the A, B, C text. Any tips?

Run("notepad.exe")
WinWaitActive("[CLASS:Notepad]")


Dim $Hotkey

HotKeySet("{F9}","Start")

Func Start()
$Hotkey = NOT $Hotkey
If $Hotkey Then ToolTip('Hotkey was pressed',0,0)
While $Hotkey
Send("{A}")
Send("{B}")
Send("{C}")
WEnd
ToolTip("")
EndFunc
Link to comment
Share on other sites

you need some empty loop to keep the script alive or the script will exit as soon as its done waiting for window

so below HotKeySet add another empty while 1 loop to keep it alive

and instead Send("{A}") you can use Send("A") or Send("ABC")

Edited by bogQ

TCP server and client - Learning about TCP servers and clients connection
Au3 oIrrlicht - Irrlicht project
Au3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related)



460px-Thief-4-temp-banner.jpg
There are those that believe that the perfect heist lies in the preparation.
Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost.

 
Link to comment
Share on other sites

some ideas about your code can be

declare some var on top of the script to be 0

on every hotkey press set it to change betwean switch var case 0 var = 1 and case 1 var = 0 and add code according to it

and you can do empty loop as func and afer var is set return it to the empty loop

Edited by bogQ

TCP server and client - Learning about TCP servers and clients connection
Au3 oIrrlicht - Irrlicht project
Au3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related)



460px-Thief-4-temp-banner.jpg
There are those that believe that the perfect heist lies in the preparation.
Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost.

 
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...