AHK Not working and keeps breaking

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Fraskii
Posts: 3
Joined: 31 Oct 2018, 14:37
Contact:

AHK Not working and keeps breaking

04 Aug 2019, 02:04

Hi,

So recently I decided to make a AHK script for Premiere Pro, but for some reason, the simplest code is giving me trouble. So at first, ImageSearch was working fine, doing it's job and then after a few runs of the script, it just breaks. All of the sudden it doesn't find the image anymore, and at some points AHK wouldn't even send out inputs. Like CTRL+D. I got no idea why it's doing this, but AHK has been overall a pretty bad experience so far. Extremely unstable and keeps breaking. If anyone could help me out that'd be great. I haven't lost all hope yet.

Code: Select all

#SingleInstance ;only one instance of this script may run at a time!

#IfWinActive ahk_exe Adobe Premiere Pro.exe

F1::
send, +7
sleep 5
send, +f
sleep 5
SendRaw, Cross Dissolve
sleep 5
ImageSearch, OutputX, OutputY, 0, 0, 1919, 1079, C:\AHK\images\cross_dissolve_icon.PNG
sleep 5
MouseMove, OutputX, OutputY, 50
SOTE
Posts: 1426
Joined: 15 Jun 2015, 06:21

Re: AHK Not working and keeps breaking

04 Aug 2019, 04:55

Usually the problem is not AutoHotkey, it is the person. It's like blaming the car for driving into a ditch and kicking it, instead of the drunk driver whose hands where on the steering wheel. Not saying there can't be mechanical problems with the car or bugs in the code, but that's often less likely the case. Things often go a lot better when the person realizes that the problem is more likely themselves, so then they strive to become more knowledgeable user and/or a better programmer.

As for your code, I noticed that you are using an extremely short duration. Sleep is in milliseconds. Per AutoHotkey help manual, 1000 milliseconds is 1 second. So if you want to wait 5 seconds, it would not be Sleep 5, instead it would be Sleep 5000. 5000 milliseconds = 5 seconds. So this might be affecting your results, without even looking at anything else yet.
User avatar
Masonjar13
Posts: 1555
Joined: 20 Jul 2014, 10:16
Location: Не Россия
Contact:

Re: AHK Not working and keeps breaking

04 Aug 2019, 13:17

SOTE is correct that you should look at yourself first, as a general rule for life, really. You're describing issues with your implementation (likely permissions), not AHK.

The biggest issue people have is not running as administrator. For most of AHK to work properly, it needs admin privileges.

Secondly, while not explicitly noted, #IfWinActive is deprecated. It outright doesn't work in H (crashes on close), and will be removed in v2, I'm pretty sure. You should consider using #if winActive() instead. In your case, #if winActive("ahk_exe Adobe Premiere Pro.exe").

As mentioned, 5 is too low of an increment for sleep. Due to how Windows works, 10ms is the minimum sleep (this is stated on the sleep page). 1-9 will simply be shifted to 10ms instead, or 15.6 if you're on XP or older.

Finally, you don't have a return. Returns are extremely important, as they say when execution of a subroutine or function should stop. Drifting off the end of the script I believe acts as a return, as a safety feature. Though, that should never be relied upon.

Another note: ImageSearch does not always work correctly, and if you have issues with that in particular, you need to look into GDI+/Gdip. Or, you may use this function, which utilizes the Gdip library.
OS: Windows 10 Pro | Editor: Notepad++
My Personal Function Library | Old Build - New Build
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: AHK Not working and keeps breaking

04 Aug 2019, 14:25

define "breaks after a few runs of the script". breaks after uve hit F1 a bunch of times or break after actually re-running and restarting the whole script?
its impossible to tell whats wrong with this script without being there to observe what it does. if thats ur whole script, sending those keystrokes(i dont know what they do in premiere) might be opening and focusing new windows, throwing ur ImageSearch coordinates off
if by "AHK wouldn't even send out inputs" u mean pressing F1 doesnt trigger the hotkey function, either ur #If condition hasnt been fulfilled(the active window is not adobepremier.exe) or something(premiere or another (intentionally) misbehaving program) might have overridden ur keyboard hook, effectively disabling F1
if u mean that it isnt sending +7 and the SendRaw stuff, make sure the keystrokes arent being dumped into something that has no way of handling them
no idea what the relevance of ^D is. u have neither defined it as a hotkey nor are u sending it.
AHK has been overall a pretty bad experience so far. Extremely unstable and keeps breaking.
ahk isnt without its flaws, but come on lol
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: AHK Not working and keeps breaking

05 Aug 2019, 02:15

@Masonjar13, hi. Note that #ifwinXXX is not deprecated in v1, not even implicitly. An important note about #if (expression)
#if wrote: Expression evaluation can only be performed by the script's main thread (at the OS level, not a quasi-thread), not directly by the keyboard/mouse hook. If the script is busy or unresponsive, such as if a FileCopy is in progress, expression evaluation is delayed and may time out.
This does not apply to #ifwinXXX which performs better than #if for simple cases. In v2 #if winXXX("literal string") has been optimised and replaces #ifWinXXX literal string. For AHK_H, I don't know.
The biggest issue people have is not running as administrator. For most of AHK to work properly, it needs admin privileges.
Hehe, I wouldn't say you need admin privileges for the vast majority of AHK functionality ;) . There is a note in the docs about troubleshooting which mentions admin, see :arrow: How do I work around problems caused by User Account Control (UAC)?.

Cheers.
User avatar
Masonjar13
Posts: 1555
Joined: 20 Jul 2014, 10:16
Location: Не Россия
Contact:

Re: AHK Not working and keeps breaking

05 Aug 2019, 08:30

Perhaps I should expand a bit on that. Using ScriptUp, which runs H due to L not having multi-threading, #ifxxx crashes the thread on exiting, therefore I've personally deprecated it (this has nothing to do with my implementation, I've checked). It's also extremely limited, but as you said, does work for simple cases.
Helgef wrote: Hehe, I wouldn't say you need admin privileges for the vast majority of AHK functionality ;) .
I would have to disagree with this sentiment, concerning Windows 10 at the very least.
Hotkeys are also blocked, so for instance, a non-elevated program cannot spy on input intended for an elevated program.
Even on W7, most scripts I write require admin rights. Sometimes I forget to force it when giving scripts to my peers and they always have issues.
OS: Windows 10 Pro | Editor: Notepad++
My Personal Function Library | Old Build - New Build
SOTE
Posts: 1426
Joined: 15 Jun 2015, 06:21

Re: AHK Not working and keeps breaking

05 Aug 2019, 19:10

As it's been mentioned a couple of times, for the sake of the OP, posting the simple version of the code for running the script with admin privileges.

Code: Select all

#SingleInstance force ;only one instance of this script may run at a time!

If not A_IsAdmin 
{
   Run *RunAs "%A_ScriptFullPath%"
   ExitApp
}
Placed towards the top, and before the main contents of your script. Don't have Adobe Premiere Pro, so can't say if that's the issue, but maybe worth a try. By the way, in your example #SingleInstance looks incomplete. You need to choose an option. Per help document
#SingleInstance [force|ignore|off] choose one of three options.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: No registered users and 230 guests