Problems trying to use 2 Scripts, Capslock, a Toggle Key & Sleep or SleepTimer. Capslock is a Runaway. Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
sashaatx
Posts: 332
Joined: 27 May 2021, 08:27
Contact:

Problems trying to use 2 Scripts, Capslock, a Toggle Key & Sleep or SleepTimer. Capslock is a Runaway.

Post by sashaatx » 26 Jul 2021, 09:55

I'll make it quick. I use Logitech GHUB with LUA in tandem with AHK.

I want to fire the letter 8, which can be fired by Space or the 8 key. This i have covered.

The problem comes up in a second script, below. Where I am trying to use "C' as Capslock, for a modifier in my Lua Scipt. Logitech Lua allows for either alt, capslock, or shift to accomplish this so any of those will do.

When I engage "8", its fine on its own. But when I engage 8 + C together, capslock just spams. I assume the two sleep timers are being challenged.

I have tried learning SleepTimer, but it requires learning a separate set of syntax that I have yet to familiarize myself with. Thanks in advance. Sorry for my stupidity.


Capslock Code:

Code: Select all

#Persistent
 
$c::
	SetCapsLockState On
    sleep, 800
   	SetCapsLockState Off
      return


 

 
 ~F2::Suspend
return

   ~Pause::
    Suspend,Off
    ExitApp



Second code that seems to be triggering the first one:

Code: Select all

#Persistent
$Space::
         $8::
        While GetKeyState("Space", "P") | GetKeyState("8", "P") {
            Toggle := !Toggle
        Send {8 down}
               Sleep, 100
       
        }
        Send {8 up}   
Return


 ~F2::Suspend
Return
 

   ~PgDn::
    Suspend,Off
    ExitApp

sashaatx
Posts: 332
Joined: 27 May 2021, 08:27
Contact:

Re: Problems trying to use 2 Scripts, Capslock, a Toggle Key & Sleep or SleepTimer. Capslock is a Runaway.

Post by sashaatx » 26 Jul 2021, 10:03

My feeble attempt at settimer

Code: Select all

    #Persistent

        $c::
        SetTimer, PressTheKey, 700
        SetTimer, PressTheKey, Off
        SetTimer, ReleaseTheKey, 100
        SetTimer, ReleaseTheKey, Off

        PressTheKey:
        SetCapsLockState On
        Return

        ReleaseTheKey:
        SetCapsLockState Off
        Return

        ~F2::Suspend
        return

           ~Pause::
           Suspend,Off
           ExitApp

User avatar
mikeyww
Posts: 26437
Joined: 09 Sep 2014, 18:38

Re: Problems trying to use 2 Scripts, Capslock, a Toggle Key & Sleep or SleepTimer. Capslock is a Runaway.

Post by mikeyww » 26 Jul 2021, 10:06

If you press a hotkey and then a different hotkey before the first one finishes, the second one interrupts the first one (unless you program otherwise), and the first one resumes after the second one finishes. You can, however, adjust any of your hotkey routines, or add new ones, to accommodate various kinds of sequences.

Relevant: Critical

One recommendation would be to try to avoid the timer as a solution to your issue. Perhaps your hotkey can wait for a different key to be pressed, and then continue after that, if that is what you are trying to do.

sashaatx
Posts: 332
Joined: 27 May 2021, 08:27
Contact:

Re: Problems trying to use 2 Scripts, Capslock, a Toggle Key & Sleep or SleepTimer. Capslock is a Runaway.

Post by sashaatx » 26 Jul 2021, 10:12

mikeyww wrote:
26 Jul 2021, 10:06
If you press a hotkey and then a different hotkey before the first one finishes, the second one interrupts the first one (unless you program otherwise), and the first one resumes after the second one finishes. You can, however, adjust any of your hotkey routines, or add new ones, to accommodate various kinds of sequences.

Relevant: Critical

One recommendation would be to try to avoid the timer as a solution to your issue. Perhaps your hotkey can wait for a different key to be pressed, and then continue after that, if that is what you are trying to do.
Hi Mikey, you're always around to help quickly. Thanks as always.

So, I tend to be holding 3 or 4 keys simultaneously. Would you recommend using 4 separate scripts as I do, or all on 1? Thats a digression I suppose.

In this case, I assume I could fix this by putting this two scripts together and creating some sort of hierarchy? I treat AHK like LUA where LUA only (for lack of the right word) allows 1 action at a time. Or, its linear. From what I read, ahk scripts can do multiple things.

If I want to be able to account for both scripts, I dont expect you to write it for me. What topic in the tutorial would you recommend I read? Thanks!
https://github.com/samfisherirl
? /Easy-Auto-GUI-for-AHK-v2 ? /Useful-AHK-v2-Libraries-and-Classes : /Pulovers-Macro-Creator-for-AHKv2 :

sashaatx
Posts: 332
Joined: 27 May 2021, 08:27
Contact:

Re: Problems trying to use 2 Scripts, Capslock, a Toggle Key & Sleep or SleepTimer. Capslock is a Runaway.

Post by sashaatx » 26 Jul 2021, 10:17

mikeyww wrote:
26 Jul 2021, 10:06
If you press a hotkey and then a different hotkey before the first one finishes, the second one interrupts the first one (unless you program otherwise), and the first one resumes after the second one finishes. You can, however, adjust any of your hotkey routines, or add new ones, to accommodate various kinds of sequences.

Relevant: Critical

One recommendation would be to try to avoid the timer as a solution to your issue. Perhaps your hotkey can wait for a different key to be pressed, and then continue after that, if that is what you are trying to do.
Correction: I would edit my post but the stupid comment I made is being approved by mods, so Im posting two comments in an attempt to beat myself to the reply.

You sent a link, regarding prioritizing. If I want to do these things paralelle to eachother, would you recommend trying to find a way not to use capslock, and other modifiers? What woulnd you say the path of least resistance is.
https://github.com/samfisherirl
? /Easy-Auto-GUI-for-AHK-v2 ? /Useful-AHK-v2-Libraries-and-Classes : /Pulovers-Macro-Creator-for-AHKv2 :

User avatar
mikeyww
Posts: 26437
Joined: 09 Sep 2014, 18:38

Re: Problems trying to use 2 Scripts, Capslock, a Toggle Key & Sleep or SleepTimer. Capslock is a Runaway.  Topic is solved

Post by mikeyww » 26 Jul 2021, 10:52

The modifiers easiest to use are Shift and Ctrl. The next preferable group (just my opinion) would be Win and Alt. CapsLock can be tricky but is possible; it does work as a prefix key in conjunction with single individual additional keys. Win and Alt sometimes cause issues that require special handling or adjustments. Having said that, I regularly and successfully use a lot of hotkeys with both of those.

Nonetheless: AHK documentation notes that it does not support the holds of more than two keys at a time (aside from modifiers noted above). You can sometimes work around this by using GetKeyState() (have a look at that and about prefix keys ), but documentation notes that AHK's behavior in handling this (e.g., a prefixed hotkey plus a directive like "#If" with a GetKeyState()) may be inconsistent.

I would use a single script, and see if you can work with modifier keys if possible. Using two scripts at the same time doesn't typically get you anywhere useful if it is just meant to be a workaround to hotkeys. In such cases, it usually makes things worse due to conflicting keyboard hooks and hotkeys.

If you are pressing two keys at the same time, you can use a prefixed hotkey, or have a routine that checks the state of the other key that is not a hotkey. Another approach can use SetTimer to do separate things with separate hotkeys. Using a Sleep for the purpose of waiting for another key seems like it would eventually be unreliable or inconsistent due to other things happening with the computer. One can use KeyWait, Input, or other approaches if needed, or just use other hotkeys that are coordinated with the initial one.

Post Reply

Return to “Ask for Help (v1)”