Jump to content

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

Using AHK with Task Scheduler


  • Please log in to reply
21 replies to this topic
niraxar
  • Members
  • 17 posts
  • Last active: Dec 17 2013 08:41 AM
  • Joined: 01 Apr 2011
Has anybody used AHK with Task scheduler ? If so please confirm whether you also face the following problems --

1. Using Send/ControlSend/etc always 'presses' the key corresponding to the character, not the actual character .. so A gets converted to a and ~ gets converted to ` ... moreover appending + does not seem to have any effect. The problem occurs when it is run from the task scheduler and the user has locked the screen either by pressing Win+L or is automatically locked. Further, the problem is aggravated if the compiled script is run.

2. The command #EscapeChar does not seem to work if run from the task scheduler and screen-locked user.

3. Even the usual escaped character control ` does not work correctly ... for example, ``/ is not interpreted as `/ but as `? which is totally beyond what it should normally do.

Converting A to a is itself an irritant but not being able to send ~ when being run from a task scheduler is quite annoying as I need to task schedule some commands of cygwin .. and ~ is frequently used in cygwin. Sure, I have workarounds, which involve somehow getting away without ~ at all. But I would like to know a way to send ~ when the script is run by the task scheduler while the user is logged/locked out ... i have tried many command Send, Control, ControlSend, ControlSendRaw, etc ... none seems to do the job.

I have started using AHK only from last week, so I am not confident to call it a bug yet ...

Thanks is advance for any help ..

niraxar
  • Members
  • 17 posts
  • Last active: Dec 17 2013 08:41 AM
  • Joined: 01 Apr 2011
i must add that if run directly by the user via Task Scheduler -> Right click -> run, there does not seem to be any problem ... only if the task scheduler runs the script on its own at the scheduled time.

hypnotic
  • Members
  • 1 posts
  • Last active: Jun 16 2011 12:56 PM
  • Joined: 21 Apr 2011
I have also had trouble using ahk with win scheduler. The scripts don't function properly when the scheduler runs the script. I am a scripting newb so I thought that was my problem :lol:

niraxar
  • Members
  • 17 posts
  • Last active: Dec 17 2013 08:41 AM
  • Joined: 01 Apr 2011
i dont know if anybody is still tracking this issue ... certainly i am, coz i raised it ... so now i propose a solution for this.

it is probably the key input rate that creates this problem. using the directive

#SetKeyDelay, 70

will usually cause the inputs to behave nicely. setting it below the number 50 doesn't do any good.

also if one uses

#SetKeyDelay,-1, 5

it also works. it may also help to set

Process, Priority,, high



but the problem with above approach is that if you happen to be using the keyboard at the time, it interferes with the script and since #setKeyDelay increases the overall execution time, it also increases the chances of interference.

for that you may use

#BlockInput, on

just before using ControlSend

and do a

#BlockInput, off

immediately afterward.

If your computer is unusually active at the time of script execution, the problem may still persist but in all normal cases the above hack works.

mediaman09
  • Members
  • 23 posts
  • Last active: Jul 12 2011 02:37 AM
  • Joined: 26 Jun 2011
Thank you for posting this.

I have the exact same issue, ie

-script works when executed manually
-script works when exectuted in TS as right click Run
-script does not work when scheduled (even though TS reports it runs successfully.

I am testing out the SetKeyDelay now.

Let me ask this:

1) when you schedule the script, are you telling it to run the ahk file or a compiled exe file? I am using exe.

2) I found I had to remove the # completely in front of SetKeyDelay ; AutoHotkey complained it did not recognize the command with it there. Just curious why.

poo_noo
  • Members
  • 251 posts
  • Last active: May 23 2014 02:52 AM
  • Joined: 08 Dec 2006

i must add that if run directly by the user via Task Scheduler -> Right click -> run, there does not seem to be any problem ... only if the task scheduler runs the script on its own at the scheduled time.


I have encountered this problem once and found out that I had typed in the wrong password when setting up the task. It seems that The windows task scheduler wizard will alert you to mismatched passwords but not to wrong passwords.

niraxar
  • Members
  • 17 posts
  • Last active: Dec 17 2013 08:41 AM
  • Joined: 01 Apr 2011

1) when you schedule the script, are you telling it to run the ahk file or a compiled exe file? I am using exe.

2) I found I had to remove the # completely in front of SetKeyDelay ; AutoHotkey complained it did not recognize the command with it there. Just curious why.


1) I too use the exe file.
2) sorry, it was a mistake. setkeydelay has no # with it. in my script i had used the correct form - setkeydelay.

# directives are used for window specific commands.

niraxar
  • Members
  • 17 posts
  • Last active: Dec 17 2013 08:41 AM
  • Joined: 01 Apr 2011
I now use these directives -

Process, Priority,, High
DetectHiddenWindows, On
SetKeyDelay, 30, 10
KeyWait, LButton, L T2
KeyWait, MButton, L T2
KeyWait, RButton, L T2

BlockInput is apparently not necessary and is a big hindrance if the script runs while you are working on your computer. But I have found that if the computer is very busy, all keys are pressed twice by the script. so the string "ren blah blah" is rendered as "rreenn bbllaahh bbllaahh". i dont know any way of avoiding it.

This happens esp when a download has just started or is about to close. Strangely when the download is going on, it does not happen, even if the download speed is more than 2-3 MBPS. I have no idea why.

mediaman09
  • Members
  • 23 posts
  • Last active: Jul 12 2011 02:37 AM
  • Joined: 26 Jun 2011

I now use these directives -

Process, Priority,, High
DetectHiddenWindows, On
SetKeyDelay, 30, 10
KeyWait, LButton, L T2
KeyWait, MButton, L T2
KeyWait, RButton, L T2


I will give those a shot as well, Thanks !

SetKeyDelay alone didnt fix the problem.

I will play with passwords as well per poo_noo;s post.

mediaman09
  • Members
  • 23 posts
  • Last active: Jul 12 2011 02:37 AM
  • Joined: 26 Jun 2011
For me it's getting worse now.

Exe runs perfect but in TS:
Its not being run when scheduled
Even a right click Run does nothing.
Yet TS coninues to report success for both conditions to report it ran successfully.

Pretty stumped now

I have TS set to run whether logged in or not

niraxar
  • Members
  • 17 posts
  • Last active: Dec 17 2013 08:41 AM
  • Joined: 01 Apr 2011
whether other tasks run correctly in TS ? maybe some windows service is shutdown.

mediaman09
  • Members
  • 23 posts
  • Last active: Jul 12 2011 02:37 AM
  • Joined: 26 Jun 2011
I think I have it solved now, as even CALC was not working !

Steps taken:

Windows Services

- Verified RPC service was running ( it was not)
- Confirmed Task Scheduler was running ( it was)
Task Scheduler
- Created new clean tasks via Create Basic Task
- Set to ONLY Run when logged in
- scheduled the EXE
AutoHotKey
- SetKeyDelay, 70
- Process, Priority,, high
- Compiled to EXE

So far it seems to be behaving. Yay !

niraxar
  • Members
  • 17 posts
  • Last active: Dec 17 2013 08:41 AM
  • Joined: 01 Apr 2011
very good !!

plz try to do one more thing. set a large download to start (or some other way to keep your computer busy, like open 30 tabs of firefox simultaneously maybe by opening a large number of bookmarks all at once) and then run your AHK exe ... i would like to know whether the double character printing happens with you too.

mediaman09
  • Members
  • 23 posts
  • Last active: Jul 12 2011 02:37 AM
  • Joined: 26 Jun 2011

very good !!

plz try to do one more thing. set a large download to start (or some other way to keep your computer busy, like open 30 tabs of firefox simultaneously maybe by opening a large number of bookmarks all at once) and then run your AHK exe ... i would like to know whether the double character printing happens with you too.


If I do get the double characters, I will certainly let you know.

It ran unattended last night, but, to my surprise. it did not run unattended this morning (TS says it did) so I guess I am not out of the woods just yet !! :(

A bit frustrating whne its this unstable. I guess I will need to let it run a few days without tweaking anything and see if I find a pattern.

mediaman09
  • Members
  • 23 posts
  • Last active: Jul 12 2011 02:37 AM
  • Joined: 26 Jun 2011
I am always logged in.

When I select "Run only hen logged in ", it seems to work but ONLY if the machine is unlocked, ie it will interrupt me if I am using the computer. But if I step away, screen saver steps in etc, and the computer is in a state where it is locked (ie logged in but requiring a password), it wont run.

I am going back to "Run whether logged in or not" ...where TS asks for the password when saving the task., to see if that makes a difference.