While GetKeyState Issue with jaco0646 user defined dynamic hotkeys script

Get help with using AutoHotkey and its commands and hotkeys
Nator
Posts: 4
Joined: 11 Jun 2018, 18:41

While GetKeyState Issue with jaco0646 user defined dynamic hotkeys script

14 Jun 2018, 15:01

Hi, I'm trying to do a while getkeystate with the user defined dynamic hotkeys from user jaco0646. Thanks to him for this awesome script.

My code is supposed to run in Label3, and do a loop while the defined hotkey is pressed, but I can't seem to figure why it won't start. I tried replacing ThisHotKey with other variables like HK3, savedHK3. Tried with tilde, without, with %, without. I need to be able to break from the loop while releasing the key.

I don't know why my key press isn't detected. If I run this in label 3, it works:
MsgBox,% A_ThisLabel "`n" A_ThisHotkey

Code: Select all

#SingleInstance force
#NoEnv
SetBatchLines, -1

#ctrls = 5  ;How many Hotkey controls to add.
Loop,% #ctrls {
 Gui, Add, Text, xm, Enter Hotkey #%A_Index%:
 IniRead, savedHK%A_Index%, Hotkeys.ini, Hotkeys, %A_Index%, %A_Space%
 If savedHK%A_Index%                                       ;Check for saved hotkeys in INI file.
  Hotkey,% savedHK%A_Index%, Label%A_Index%                 ;Activate saved hotkeys if found.
 StringReplace, noMods, savedHK%A_Index%, ~                  ;Remove tilde (~) and Win (#) modifiers...
 StringReplace, noMods, noMods, #,,UseErrorLevel              ;They are incompatible with hotkey controls (cannot be shown).
 Gui, Add, Hotkey, x+5 vHK%A_Index% gLabel, %noMods%           ;Add hotkey controls and show saved hotkeys.
 Gui, Add, CheckBox, x+5 vCB%A_Index% Checked%ErrorLevel%, Win  ;Add checkboxes to allow the Windows key (#) as a modifier...
}                                                                ;Check the box if Win modifier is used.
Gui, Show,,Dynamic Hotkeys
return
GuiClose:
 ExitApp

Label:
 If %A_GuiControl% in +,^,!,+^,+!,^!,+^!    ;If the hotkey contains only modifiers, return to wait for a key.
  return
 num := SubStr(A_GuiControl,3)              ;Get the index number of the hotkey control.
 If (HK%num% != "") {                       ;If the hotkey is not blank...
  Gui, Submit, NoHide
  If CB%num%                                ;  If the 'Win' box is checked, then add its modifier (#).
   HK%num% := "#" HK%num%
  If !RegExMatch(HK%num%,"[#!\^\+]")        ;  If the new hotkey has no modifiers, add the (~) modifier.
   HK%num% := "~" HK%num%                   ;    This prevents any key from being blocked.
  Loop,% #ctrls
   If (HK%num% = savedHK%A_Index%) {        ;  Check for duplicate hotkey...
    dup := A_Index
    Loop,6 {
     GuiControl,% "Disable" b:=!b, HK%dup%  ;    Flash the original hotkey to alert the user.
     Sleep,200
    }
    GuiControl,,HK%num%,% HK%num% :=""      ;    Delete the hotkey and clear the control.
    break
   }
 }
 If (savedHK%num% || HK%num%)
  setHK(num, savedHK%num%, HK%num%)
return

setHK(num,INI,GUI) {
 If INI
  Hotkey, %INI%, Label%num%, Off
 If GUI
  Hotkey, %GUI%, Label%num%, On
 IniWrite,% GUI ? GUI:null, Hotkeys.ini, Hotkeys, %num%
 savedHK%num%  := HK%num%
 TrayTip, Label%num%,% !INI ? GUI " ON":!GUI ? INI " OFF":GUI " ON`n" INI " OFF"
}

;These labels may contain any commands for their respective hotkeys to perform.
Label1:
;my code isn't finished yet
return

Label2:
;my code isn't finished yet
return

Label3:
;MsgBox,% A_ThisLabel "`n" A_ThisHotkey (This msgbox works flawlessly, but the next code doesn't)

While GetKeyState(ThisHotKey, "P")
{Loop,4 
	{
	Send {1)
	Sleep 500
	if not GetKeyState(ThisHotKey, "P")
	break
	Send {2)
	Sleep 500
	if not GetKeyState(ThisHotKey, "P")
	break
	Send {3) 
}
return

Label4:
;my code isn't finished yet
return

Label5:
;my code isn't finished yet
return

Return to “Ask For Help”

Who is online

Users browsing this forum: Bing [Bot], JoeWinograd and 61 guests