Help to understand Hotkey Script Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
manehscripts
Posts: 126
Joined: 03 May 2019, 16:10

Help to understand Hotkey Script

11 Jun 2019, 22:35

I have a script that I'm trying to understand and fix because it's memorizing the Hotkey that is configured and still executing even when disable SetTimer. I can change Hotkey, but when I return to the previous one, it does not work (see the gif below) I can't understand the problem, and I need someone's help, please.
exemplo10.gif
exemplo10.gif (569.15 KiB) Viewed 904 times

Code: Select all

Gui, Font, s12
Gui, Add, Text, x20, Press your Hotkey below:
Gui, Add, Hotkey, w200 vHKV gLabel
Gui, Add, Checkbox, x20 vActive gActiveHotkeyG, Active Hotkey
Gui, Show, w240 h120, `t
return
toggle := 0
ActiveHotkeyG:
  toggle := !toggle
  if (toggle) {
    GuiControl, disable, HKV
    GuiControl, disable, Hotkey
    SetTimer, Script, 1
  } else {
    GuiControl, enable, HKV
    GuiControl, enable, Hotkey
    SetTimer, Script, Off
  }
return

Script:
    if (Active) {
        Label:
            if HKV in +,^,!,+^,+!,^!,+^!
        return

        if (savedHK) { 
            Hotkey, %savedHK%, Label1, Off
        }

        if (HKV = "") {
            savedHK =
            return
        }
        
		if (StrLen(HKV)) {
			Hotkey, %HKV%, Label1, 1
			savedHK := HKV
		}
        return
        
        Label1:
			MsgBox, %savedHK%
        return
	}
return

Esc::ExitApp
GuiClose:
ExitApp
-----------------------------------------------------------
Stop to think, shut up to resist, and act to win!
User avatar
YoucefHam
Posts: 372
Joined: 24 Aug 2015, 12:56
Location: Algeria
Contact:

Re: Help to understand Hotkey Script

12 Jun 2019, 00:25

try this

Code: Select all

Gui, Font, s12
Gui, Add, Text, x20, Press your Hotkey below:
Gui, Add, Hotkey, w200 vHKV
Gui, Add, Checkbox, x20 vActive gActiveHotkeyG, Active Hotkey
Gui, Show, w240 h120, `t
return


ActiveHotkeyG:
  Gui, Submit, NoHide
  if (Active)
  {
    GuiControl, disable, HKV
    Hotkey, % HKV, On, UseErrorLevel
    Hotkey, % HKV, Label1, 1
  }
  else
  {
    Hotkey, % HKV, Label1, Off
    GuiControl, enable, HKV
  }
return

Label1:
MsgBox, % A_ThisHotkey
return


Esc::ExitApp
GuiClose:
ExitApp
:wave: There is always more than one way to solve a problem. ;)
User avatar
manehscripts
Posts: 126
Joined: 03 May 2019, 16:10

Re: Help to understand Hotkey Script

12 Jun 2019, 00:28

YoucefHam wrote:
12 Jun 2019, 00:25
try this

Code: Select all

Gui, Font, s12
Gui, Add, Text, x20, Press your Hotkey below:
Gui, Add, Hotkey, w200 vHKV
Gui, Add, Checkbox, x20 vActive gActiveHotkeyG, Active Hotkey
Gui, Show, w240 h120, `t
return


ActiveHotkeyG:
  Gui, Submit, NoHide
  if (Active)
  {
    GuiControl, disable, HKV
    Hotkey, % HKV, On, UseErrorLevel
    Hotkey, % HKV, Label1, 1
  }
  else
  {
    Hotkey, % HKV, Label1, Off
    GuiControl, enable, HKV
  }
return

Label1:
MsgBox, % A_ThisHotkey
return


Esc::ExitApp
GuiClose:
ExitApp
Thank you my friend!
@YoucefHam Bro, Can you make Hotkey (when enabled) work only when a certain window is enabled IfWinActive?
-----------------------------------------------------------
Stop to think, shut up to resist, and act to win!
User avatar
YoucefHam
Posts: 372
Joined: 24 Aug 2015, 12:56
Location: Algeria
Contact:

Re: Help to understand Hotkey Script

12 Jun 2019, 14:59

try this

Code: Select all

Gui, Font, s12
Gui, Add, Text, x20, Press your Hotkey below:
Gui, Add, Hotkey, w200 vHKV
Gui, Add, Checkbox, x20 vActive gActiveHotkeyG, Active Hotkey
Gui, Show, w240 h120, `t
return


ActiveHotkeyG:
  Gui, Submit, NoHide
  if (Active)
  {
    GuiControl, disable, HKV
	
    Hotkey, IfWinActive, ahk_exe notepad.exe
	
    Hotkey, % HKV, On, UseErrorLevel
    Hotkey, % HKV, Label1, 1
  }
  else
  {
    Hotkey, % HKV, Label1, Off
    GuiControl, enable, HKV
  }
return

Label1:
MsgBox, % A_ThisHotkey
return


Esc::ExitApp
GuiClose:
ExitApp
:wave: There is always more than one way to solve a problem. ;)
User avatar
manehscripts
Posts: 126
Joined: 03 May 2019, 16:10

Re: Help to understand Hotkey Script

12 Jun 2019, 16:06

@YoucefHam thanks, but it did not work :(
exemplo11.gif
exemplo11.gif (325.37 KiB) Viewed 817 times
-----------------------------------------------------------
Stop to think, shut up to resist, and act to win!
User avatar
YoucefHam
Posts: 372
Joined: 24 Aug 2015, 12:56
Location: Algeria
Contact:

Re: Help to understand Hotkey Script  Topic is solved

12 Jun 2019, 16:18

Hotkey, IfWinActive, WindowTitle HotKey work only in this window called "WindowTitle"

Hotkey, IfWinActive, ahk_exe notepad.exe work in all windows running from "notepad.exe" process

in your case Hotkey, IfWinActive, Calculadora

Code: Select all

Gui, Font, s12
Gui, Add, Text, x20, Press your Hotkey below:
Gui, Add, Hotkey, w200 vHKV
Gui, Add, Checkbox, x20 vActive gActiveHotkeyG, Active Hotkey
Gui, Show, w240 h120, `t
return


ActiveHotkeyG:
  Gui, Submit, NoHide
  if (Active)
  {
    GuiControl, disable, HKV
	
    Hotkey, IfWinActive, Calculadora
	
    Hotkey, % HKV, On, UseErrorLevel
    Hotkey, % HKV, Label1, 1
  }
  else
  {
    Hotkey, % HKV, Label1, Off
    GuiControl, enable, HKV
  }
return

Label1:
MsgBox, % A_ThisHotkey
return


Esc::ExitApp
GuiClose:
ExitApp
:wave: There is always more than one way to solve a problem. ;)
User avatar
manehscripts
Posts: 126
Joined: 03 May 2019, 16:10

Re: Help to understand Hotkey Script

12 Jun 2019, 16:23

YoucefHam wrote:
12 Jun 2019, 16:18
Hotkey, IfWinActive, WindowTitle HotKey work only in this window called "WindowTitle"

Hotkey, IfWinActive, ahk_exe notepad.exe work in all windows running from "notepad.exe" process

in your case Hotkey, IfWinActive, Calculadora

Code: Select all

Gui, Font, s12
Gui, Add, Text, x20, Press your Hotkey below:
Gui, Add, Hotkey, w200 vHKV
Gui, Add, Checkbox, x20 vActive gActiveHotkeyG, Active Hotkey
Gui, Show, w240 h120, `t
return


ActiveHotkeyG:
  Gui, Submit, NoHide
  if (Active)
  {
    GuiControl, disable, HKV
	
    Hotkey, IfWinActive, Calculadora
	
    Hotkey, % HKV, On, UseErrorLevel
    Hotkey, % HKV, Label1, 1
  }
  else
  {
    Hotkey, % HKV, Label1, Off
    GuiControl, enable, HKV
  }
return

Label1:
MsgBox, % A_ThisHotkey
return


Esc::ExitApp
GuiClose:
ExitApp
:bravo: :bravo: :bravo: :bravo:
-----------------------------------------------------------
Stop to think, shut up to resist, and act to win!

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Chunjee, Descolada, Mateusz53, peter_ahk, Rohwedder and 171 guests