Page 1 of 1

Script only runs once

Posted: 24 Apr 2019, 12:09
by shiro_design
HI, I have simple script that plays a gif when the control key is pressed down. It closes when the control is released. My goal with this is to create very short how to vids when a key is pressed. I'm new to autohotkey so i'm picking this up as i go along. I have no real experience in coding. So i've put this together from bits I've found.The problem i have with the script is it only runs once even if i put the #Persistent tag. I want this to be there in the background so whenever the user holds down the key the animation plays.

#SingleInstance force
#Persistent

~ctrl::
keywait, Ctrl, D
file := "C:\Users\JV\Desktop\GIFAHK\kanye.gif"
Gui, Margin, 1, 1
Gui, +HwndhWndGifAnim +Resize +LabelGifAnimationSampleGui ; Set it

resizable
AnimatedGifControl(hWndGifAnim, file, "hWndhWndGifAnimControl")
Gui, Show,, Animated Gif Gui Control Sample 3


GifAnimationSampleGuiSize:
GuiControl, Move, % hWndGifAnimControl, % "H" (A_GuiHeight-20) " W"

(A_GuiWidth-20)


keywait, Ctrl,
WinActivate, Animated Gif Gui Control Sample 3,
WinWaitActive, Animated Gif Gui Control Sample 3,
WinKill, Animated Gif Gui Control Sample 3
MsgBox You released control key
return

Re: Script only runs once

Posted: 24 Apr 2019, 17:21
by Osprey
It stays running for me. I had to comment out the AnimatedGifControl() function call, though, because you didn't provide that. That could mean that that function is exiting the script, either deliberately or by crashing.

Re: Script only runs once

Posted: 26 Apr 2019, 01:56
by shiro_design
For some reason it wasn't working but then after a restart it started working again. Maybe it was a bug or because i had my machine on hibernate earlier. Thanks for the reply.