Image not destroyed / shown misclicked

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
mor61
Posts: 2
Joined: 14 Feb 2019, 05:10

Image not destroyed / shown misclicked

14 Feb 2019, 05:24

Hey,

I want to show an image on the screen every time the caps lock is on, this is mostly working but every now and then when fast clicking or the script is opening something,
clicking on the capslock does not remove the message / not showing it and thus causing the message to be out of sync (caps lock is off but there is still the message / caps lock is on but there is no message).

This is the code I am using:

Code: Select all

~*CapsLock::
state := GetKeyState("CapsLock", "T")
if state = 1
{
    SplashImageGUI("command-mode.png", "center", "center", false, true)
}
else
{
    DestroySplashGUI()
}
return

SplashImageGUI(Picture, X, Y, Duration, Transparent = false)
{
Gui, XPT99:Margin , 0, 0
Gui, XPT99:Add, Picture,, %Picture%
Gui, XPT99:Color, ECE9D8
Gui, XPT99:+LastFound -Caption +AlwaysOnTop +ToolWindow -Border
If Transparent
{
Winset, TransColor, ECE9D8
}
Gui, XPT99:Show, x%X% y%Y% NoActivate
if (Duration !== false)
{
    SetTimer, DestroySplashGUI, -%Duration%
}
return
}

DestroySplashGUI()
{
Gui, XPT99:Destroy
return
}
Is there a way to make sure the image staying in sync with the image showing?
trust_me
Posts: 98
Joined: 29 Jul 2017, 10:46

Re: Image not destroyed / shown misclicked

14 Feb 2019, 12:13

Adding a sleep 10 after the hotkey seems to solve it....

Code: Select all

~*CapsLock::
sleep 10    
state := GetKeyState("CapsLock", "T")
if state = 1
{
    SplashImageGUI("command-mode.png", "center", "center", false, true)
}
else
{
    DestroySplashGUI()
}
return

SplashImageGUI(Picture, X, Y, Duration, Transparent = false)
{
Gui, XPT99:Margin , 0, 0
Gui, XPT99:Add, Picture,, %Picture%
Gui, XPT99:Color, ECE9D8
Gui, XPT99:+LastFound -Caption +AlwaysOnTop +ToolWindow -Border
If Transparent
{
Winset, TransColor, ECE9D8
}
Gui, XPT99:Show, x%X% y%Y% NoActivate
if (Duration !== false)
{
    SetTimer, DestroySplashGUI, -%Duration%
}
return
}

DestroySplashGUI()
{
Gui, XPT99:Destroy
return
}
mor61
Posts: 2
Joined: 14 Feb 2019, 05:10

Re: Image not destroyed / shown misclicked

15 Feb 2019, 05:08

trust_me wrote:
14 Feb 2019, 12:13
Adding a sleep 10 after the hotkey seems to solve it....

Code: Select all

~*CapsLock::
sleep 10    
state := GetKeyState("CapsLock", "T")
if state = 1
{
    SplashImageGUI("command-mode.png", "center", "center", false, true)
}
else
{
    DestroySplashGUI()
}
return

SplashImageGUI(Picture, X, Y, Duration, Transparent = false)
{
Gui, XPT99:Margin , 0, 0
Gui, XPT99:Add, Picture,, %Picture%
Gui, XPT99:Color, ECE9D8
Gui, XPT99:+LastFound -Caption +AlwaysOnTop +ToolWindow -Border
If Transparent
{
Winset, TransColor, ECE9D8
}
Gui, XPT99:Show, x%X% y%Y% NoActivate
if (Duration !== false)
{
    SetTimer, DestroySplashGUI, -%Duration%
}
return
}

DestroySplashGUI()
{
Gui, XPT99:Destroy
return
}
This unfortunately did not solved the problem, I have tried many variations such as toggle flag / key wait (so the hotkey won't be recalled when holding capslock).

For now I am trying another solution which seems to solve it:

Code: Select all

#If, GetKeyState("CapsLock", "T")

$~*CapsLock::
SplashImageGUI("command-mode.png", "center", "center", false, true)
Return
#If

$~*CapsLock::
DestroySplashGUI()
Return
For some reason this seems to not miss the sync between the capslock state and image

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: drlvanb, hiahkforum and 409 guests