1

I'm trying to complete an autohotkey script where you can double tap any SHIFT key twice and follow it by a certain letter to activate a macro. I have the following script but i have two "bugs" i can't figure out how to solve. I've tried other forums with no luck. Hoping someone can help me out. I'm a little new at this.

Bug 1: The macro is activated if you press any letter in between the two SHIFTs where it should only be activated if you press the SHIFTs exclusively. For example, pressing SHIFT, s, SHIFT, d will enable the macro.

Bug 2: I'm not sure how this happens but with the following code, I periodically get all or some of the macros to activate while i'm typing. It seems to happen when I type the first capital letter in a sentence. But only sometimes. For example... "bla bla bla profiles. S"

I've fooled around with the timeouts but that doesn't seem to make much of a difference. Any help is appreciated.

Thanks, Jeff.

~Shift Up::
If (A_ThisHotkey == A_PriorHotkey && A_TimeSincePriorHotkey < 400)
{
    Double_SHIFT := true
    Sleep, 2000
    Double_SHIFT := false
}
return

; Press a key within two seconds after double tapping the Shift key, to activate an action:
#If (Double_SHIFT)
    d::
    FormatTime, CurrentDateTime,,MM/dd/yy - hh:mmtt
    SendInput %CurrentDateTime%
            Double_SHIFT :=false
            return
    a:: MsgBox, Test
    s:: MsgBox, Test
    f:: MsgBox, Test
return
2
  • I can't recreate the 2nd issue.
    – errorseven
    Apr 30, 2017 at 0:18
  • Thanks so much. i'm going to test this for a while. The fix may take care of the 2nd issue. Will let you know.
    – Jeff E
    Apr 30, 2017 at 3:43

1 Answer 1

2

Fix for Bug 1:

endKeys := "{BS}{Enter}{Insert}{Home}{Pgup}{PdDwn}End}{Delete}" 
     . "{F1}{F2}{F3}{F4}{F5}{F6}{F7}{F8}{F9}{F10}{F11}{F12}"
     . "{LShift}{RShift}{Tab}{Esc}{CAPSLOCK}{Ctrl}{PrintScreen}{NumLock}" 
     . "{Numpad0}{Numpad0}{Numpad0}{Numpad0}{Numpad0}{Numpad0}{Numpad0}" 
     . "{Numpad7}{Numpad8}{Numpad9}{NumpadDel}{Up}{Down}{Left}{Right}"
     . "{LAlt}{RAlt}{.}{,}{/}"

~Alt Up::
    Input, key, V L1 t0.5 E, % endKeys
    If (Errorlevel ~= "Alt") {
        Double_ALT := true
        Sleep 2000
        Double_ALT := false
    }
return

; Press a key within two seconds after double tapping the Alt key, to activate an action:
#If (Double_ALT)
    d::
    FormatTime, CurrentDateTime,,MM/dd/yy - hh:mmtt
    SendInput %CurrentDateTime%
            Double_ALT :=false
            return
    a:: MsgBox, Test
    s:: MsgBox, Test
    f:: MsgBox, Test
return
9
  • Awsome. I'll test this out but this seems to work. Thanks! It may fix bug 2 as well. So "% endKeys means if any of the listed keys are typed in between, it cancels? I tested typing a period in between and that doesn't activate either but a period is not included. Just curious why you didn't include one in the endKeys. Thanks again!
    – Jeff E
    Apr 30, 2017 at 2:47
  • Missed one or a few, add em in. If the answer works, please accept it, so that others will know.
    – errorseven
    Apr 30, 2017 at 5:11
  • I'm still getting bug 2. It happens when i type the first capital letter of a sentence and only happens very infrequently. Very hard to reproduce on demand. Is the "endKeys" a list of keys that cancel the marco if the key is typed in between Shifts? If so wouldn't the {LShift} and {RShift} kill the marco? I thought adding {Space} and {.} would help but didn't. while writing this i just got it to happen a few times as I was typing "adding {S..." then the macro activated when i typed "p", "a", "c", and "e". still hard to reproduce but maybe that helps. Any ideas?
    – Jeff E
    May 1, 2017 at 16:07
  • I'm fairly certain this is caused by an accidental double shift or "bounce" while typing very fast. I'm going to propose to my boss to use Alt.
    – Jeff E
    May 1, 2017 at 17:17
  • Yes the EndKeys are a list of keys that cancel the Input command. It's possible also that your keyboard is the culprit. Try swapping it with a differnet model. If you can get a mechanical keyboard.
    – errorseven
    May 1, 2017 at 22:04

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.