help in hotkey coming from the gui

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
bittencourt318
Posts: 90
Joined: 16 Apr 2020, 10:57

help in hotkey coming from the gui

07 Sep 2022, 11:18

good afternoon people someone can help me as i can for a variable to trigger a script I'll leave an example more less as i wanted but I can not make it work
needed it to start as soon as I pressed the key but that key is a variation that comes from the gui hotkey


Code: Select all

#NoEnv
#SingleInstance Force
#MaxThreadsPerHotkey, 99999999
#MaxHotkeysPerInterval 99000000
#HotkeyInterval 99000000
#KeyHistory 0
CoordMode, Pixel, Screen
CoordMode, Mouse, Screen
SendMode Input
SetBatchLines -1

on := false
home := "hotkeyon"
;-----------------------------------------------------------------------------------
Gui, Add, GroupBox, x1 y1 w179 h325, ;GroupBox 1   

  Gui, Add, Text, x10 y10 w70 h20 , HOTKEY 
  
  Gui, Add, Hotkey, x120 y15 w50 h20 vhome, iniciar
  
Gui, Add, Hotkey, x10 y30 w25 h17 vHK, 1    ;====================================================
  Gui, Add, Edit, x10 y50 w35 h17 vTemp1, 2000

;Gui, Add, Text, x110 y10 w50 h20 , TEMPO 


;---------------------------------------------------------------on-off--------------

Gui, Add, Button, x60 y60 w40 h20 gonnn, ON  ;====
Gui, Add, Button, x60 y90 w40 h20 gpause, OFF

; Generated using SmartGUI Creator for SciTE
Gui, Show, w180 h330, teste
return


%home% := hotkeyon

home::   ; <<<<<<<<<<<<<<<<<<<<==========================================================================
on := !On
While on {

onnn:
Loop
ifWinExist, ahk_exe ########################
Gui, Submit, NoHide	

if (ErrorLevel = 0)
{
       {
		sleep,200
        Send, {%hk%}
        Sleep, %Temp1%	
		
		goto, atacar
       }
 if (errorLevel = 0) 
 {
   goto, atacar
  }
}
if (ErrorLevel = 1)
{
   return
}
}

return


pause:
 Pause
 return
 
 GuiClose:
ExitApp
return
Lepes
Posts: 141
Joined: 06 May 2021, 07:32
Location: Spain

Re: help in hotkey coming from the gui

07 Sep 2022, 12:15

-Run this code
- specify both hotkeys on Gui
- push ON button
- you can minimize Gui for example and focus to another window, then press hotkey defined on HK (by default is 1) so you understand that "1" has been converted to a real hotkey.

Code: Select all

#NoEnv
#SingleInstance Force
#MaxThreadsPerHotkey, 99999999
#MaxHotkeysPerInterval 99000000
#HotkeyInterval 99000000
#KeyHistory 0
CoordMode, Pixel, Screen
CoordMode, Mouse, Screen
SendMode Input
SetBatchLines -1

;on := false
;home := "hotkeyon"
;-----------------------------------------------------------------------------------
Gui, Add, GroupBox, x1 y1 w179 h325, ;GroupBox 1   

  Gui, Add, Text, x10 y10 w70 h20 , HOTKEY 
  
  Gui, Add, Hotkey, x120 y15 w50 h20 vhome
  
Gui, Add, Hotkey, x10 y30 w25 h17 vHK, 1    ;====================================================
  Gui, Add, Edit, x10 y50 w35 h17 vTemp1, 2000

;Gui, Add, Text, x110 y10 w50 h20 , TEMPO 


;---------------------------------------------------------------on-off--------------

Gui, Add, Button, x60 y60 w40 h20 gonnn, ON  ;====
Gui, Add, Button, x60 y90 w40 h20 gpause, OFF

; Generated using SmartGUI Creator for SciTE
Gui, Show, w180 h330, teste
return


;%home% := hotkeyon

;home::   ; <<<<<<<<<<<<<<<<<<<<==========================================================================
;on := !on
;While on {

onnn:
;Loop
;ifWinExist, ahk_exe ########################
Gui, Submit, NoHide	

MsgBox, First hotkey is %home% The second one is %HK%

; I can't send keys because the active window is the AutoHotkey Gui and the 
; active control would be the "ok button"
;Send, %HK%


hotkey %HK%,  HKPressed   ; create a custom hotkey from HK text and label HKPressed
return

HKPressed:
; here is the associated code to be run when custom HK hotkey is pressed
MsgBox, HK hotkey is live and came from hotkey %A_ThisHotkey%
return


pause:
 Pause
 return
 
 GuiClose:
ExitApp
return

atacar:
  Return

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Bing [Bot], mikeyww, peter_ahk, Spawnova and 348 guests