Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

[solved] - Run a script for a program in the background?


  • Please log in to reply
12 replies to this topic
Sontawila
  • Members
  • 6 posts
  • Last active: Sep 29 2011 11:30 PM
  • Joined: 28 Sep 2011
Hey guys,

I just started using AH and I LOVE IT. Saves me a lot of time doing mindless tasks.

I only have one question at this moment, is there a way to run a specific scrip linked to a specific program that is minimized/in the background so I can do other things in the system?

Thanks a lot..

TLM
  • Administrators
  • 3864 posts
  • Last active:
  • Joined: 21 Aug 2006
Welcome!
Heres a small example
detectHiddenWindows, on
run notepad,, hide, npPid
winWait % "ahk_pid " npPid
controlSetText, edit1, Some text, % "ahk_pid " npPid

msgbox 'Some Text' was written to notepad in background.`nPress OK to show.
winShow, % "ahk_pid " npPid
The things to look into:- DetectHiddenWindows
- Run ( HIDE )
- ahk_pid + ahk_id
- ControlSetText and all other control commands.
- Expressions
- Also learn how to use AU3spy.exe that comes with AHK ( run below code )
run % A_ProgramFiles "\AutoHotkey\AU3_Spy.exe"
hth

Posted Image

don't duplicate, iterate!


para000
  • Members
  • 185 posts
  • Last active: Jun 15 2014 04:12 PM
  • Joined: 08 Sep 2011
post your code here so we can help you

Sontawila
  • Members
  • 6 posts
  • Last active: Sep 29 2011 11:30 PM
  • Joined: 28 Sep 2011
Thank you very much for the replies. Unfortunately I have very little programming experience so this is a challenge for me :(

What I want to do is: launch the application, start AHK to let it do its thing and then I minimize the application/alt-tab to desktop, browser, other application...etc and have AHK work in the background without affecting me.

my simple code is as follow:
#z::pause; Press Win+z to pause. Press again to resume

#s::
Loop 
{

Send {Enter}
Sleep 2000
Send {Enter}
Sleep 2000
Send {Enter}
Sleep 4000
Send {Enter}
Sleep 4000
Send {Esc}
Sleep 4000
Send {Down}
Sleep 1500
}
return
Thanks again

para000
  • Members
  • 185 posts
  • Last active: Jun 15 2014 04:12 PM
  • Joined: 08 Sep 2011
Try this:
F6::
WinGet, programid,List, program name <------ programid = "program name"+id at the end
Loop
{
ControlSend,,{Enter}, ahk_id %programid1% <------ programid = "program name"+id1 at the end
Sleep 2000 
ControlSend,,{Enter}, ahk_id %programid1%
Sleep 2000 
ControlSend,,{Enter}, ahk_id %programid1%
Sleep 4000 
ControlSend,,{Enter}, ahk_id %programid1%
Sleep 4000 
ControlSend,,{Esc}, ahk_id %programid1%
Sleep 4000 
ControlSend,,{Down}, ahk_id %programid1%
Sleep 1500 
}
F2::pause


Sontawila
  • Members
  • 6 posts
  • Last active: Sep 29 2011 11:30 PM
  • Joined: 28 Sep 2011
Thank you para for the reply again.

Can I trouble you again by explaining the code for me a bit? :oops:

And what should I put as program name? the name.exe?

engunneer
  • Moderators
  • 9162 posts
  • Last active: Sep 12 2014 10:36 PM
  • Joined: 30 Aug 2005
program name in the WinGet command should be replaced with the Title of the target window. Also be sure to look at SetTitleMatchMode

Sontawila
  • Members
  • 6 posts
  • Last active: Sep 29 2011 11:30 PM
  • Joined: 28 Sep 2011
and what is ID?

My program win name is: Net Cafe and has more than 1 window.

engunneer
  • Moderators
  • 9162 posts
  • Last active: Sep 12 2014 10:36 PM
  • Joined: 30 Aug 2005
the WinGet command will get a list of all ids of all the windows that match the title given, then the "ahk_id %programid1%" specifies that all the keys are sent to the first window in the list of windows found.

Sontawila
  • Members
  • 6 posts
  • Last active: Sep 29 2011 11:30 PM
  • Joined: 28 Sep 2011
Ok, what happens when two windows with the same name exist? or when a new window of the same name is created?

Sontawila
  • Members
  • 6 posts
  • Last active: Sep 29 2011 11:30 PM
  • Joined: 28 Sep 2011
Thanks guys, I tried the code and it worked perfectly :)

THANK YOU!!

  • Guests
  • Last active:
  • Joined: --

Thanks guys, I tried the code and it worked perfectly :)

THANK YOU!!


do you mind posting a copy of your working code...like you im a beginner with this and has a very litle of programming

para000
  • Members
  • 185 posts
  • Last active: Jun 15 2014 04:12 PM
  • Joined: 08 Sep 2011
Your welcome. I have 2 week on AHK but i try to help people whit simple scripts i can make.