GUI Question: Why do i need to press my hotkey twice before it triggers? Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
OCP
Posts: 98
Joined: 28 Mar 2018, 19:28

GUI Question: Why do i need to press my hotkey twice before it triggers?

02 Feb 2019, 14:30

hello i am in need of some help / a pointer to help me understand why this does not work.

i am trying to get this gui to set the hotkey times pressed counter to 0 after i pressed minimize but i cant get it done i keep having to press my hotkey twice to get it to pop up again (after i used minimize). what am i missing here? is it not possible to do this in a function?

Code: Select all

#SingleInstance, Force

LWin::
    hotkeygui++      
if hotkeygui = 1 
	{
		Gui,1: +Owner +AlwaysOnTop 
		Gui,1: Add, Button, x0 y0 w200 h30 , Button
		Gui,1: Show, w200 h30, Test GUI
		Gui,1: Submit, NoHide
		OnMessage(0x112, "WM_SYSCOMMAND")
		return
    }
else if hotkeygui = 2
    {  
	    Gui,1: Destroy	
	    hotkeygui = 0
	    return 
	}

GuiClose:
ExitApp

WM_SYSCOMMAND(wMessage)
{
   If wMessage = 61472
    {   
        Gui,1: Destroy
        hotkeygui = 0
		return 
    }
}
thank you for your time
OCP
Posts: 98
Joined: 28 Mar 2018, 19:28

Re: GUI Question: Why do i need to press my hotkey twice before it triggers?

02 Feb 2019, 15:28

solved it

Code: Select all

#SingleInstance, Force

LWin::
    hotkeygui++      
if hotkeygui = 1 
	{
		Gui,1: +Owner +AlwaysOnTop 
		Gui,1: Add, Button, x0 y0 w200 h30 , Button
		Gui,1: Show, w200 h30, Test GUI
		Gui,1: Submit, NoHide
		OnMessage(0x112, "WM_SYSCOMMAND")
		return
    }
else if hotkeygui = 2
    {  
	    Gui,1: Destroy	
	    hotkeygui = 0
	    return 
	}

GuiClose:
ExitApp

WM_SYSCOMMAND(wMessage)
{
   If wMessage = 61472
    {   
        Gui,1: Destroy
        GoSub, GuiCounter
    }
}

GuiCounter:
hotkeygui = 0
return 
just me
Posts: 9458
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: GUI Question: Why do i need to press my hotkey twice before it triggers?  Topic is solved

03 Feb 2019, 05:38

Variables in functions are local by default: Local and Global Variables

Either

Code: Select all

#SingleInstance, Force
Global hotkeygui := 0 ; declare hotkeygui as super-global
Return

LWin::
...
or

Code: Select all

WM_SYSCOMMAND(wMessage)
{
   Global hotkeygui ; declare hotkeygui as global
   If wMessage = 61472
   {
      Gui,1: Destroy
      hotkeygui = 0
      return
   }
}
OCP
Posts: 98
Joined: 28 Mar 2018, 19:28

Re: GUI Question: Why do i need to press my hotkey twice before it triggers?

03 Feb 2019, 06:09

just me wrote:
03 Feb 2019, 05:38
Variables in functions are local by default: Local and Global Variables

Either

Code: Select all

#SingleInstance, Force
Global hotkeygui := 0 ; declare hotkeygui as super-global
Return

LWin::
...
or

Code: Select all

WM_SYSCOMMAND(wMessage)
{
 Global hotkeygui ; declare hotkeygui as global
 If wMessage = 61472
 {
 Gui,1: Destroy
 hotkeygui = 0
 return
 }
}
thank you for clarifying that for me i appreciate that

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot], mikeyww and 184 guests