topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • Tuesday October 15, 2024, 6:59 am
  • Proudly celebrating 15+ years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: Help fixing bugs in AutoHotKey SHIFT/SHIFT activate key  (Read 12849 times)

jeff_eisenberg

  • Participant
  • Joined in 2017
  • *
  • default avatar
  • Posts: 8
    • View Profile
    • Donate to Member
Help fixing bugs in AutoHotKey SHIFT/SHIFT activate key
« on: April 29, 2017, 06:36 PM »
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
« Last Edit: April 29, 2017, 07:30 PM by jeff_eisenberg »

IainB

  • Supporting Member
  • Joined in 2008
  • **
  • Posts: 7,543
  • @Slartibartfarst
    • View Profile
    • Read more about this member.
    • Donate to Member
Re: Help fixing bugs in AutoHotKey SHIFT/SHIFT activate key
« Reply #1 on: May 01, 2017, 03:23 AM »
@jeff_eisenberg:
Sorry, but the script seems to work fine for me.   :(
That is, it works and I couldn't provoke any errors. However, the script conflicts with some of my existing AHK hotkeys where I use hotkey combos Left-Shift+RightShift+(another character) to trigger various functions, so the Left-Shift+RightShift triggers your script (which would seem to be what one would expect, so nothing wrong there.

Maybe therein lies a possible answer? - i.e., it might be conflicting with some of your own existing hotkeys?
Another possibility: Is your Shift key bouncing (i.e., not mechanically sound)?

If you cannot consistently reproduce the error(s), then it might well be something variable/unpredictable like that.
Just a thought.
« Last Edit: May 01, 2017, 12:05 PM by IainB »

IainB

  • Supporting Member
  • Joined in 2008
  • **
  • Posts: 7,543
  • @Slartibartfarst
    • View Profile
    • Read more about this member.
    • Donate to Member
Re: Help fixing bugs in AutoHotKey SHIFT/SHIFT activate key
« Reply #2 on: May 01, 2017, 09:26 AM »
@jeff_eisenberg:
Ah, I knew this problem seemed a tad familiar. My subconscious eventually dug it out.
It looks lke it might be the "tap-tap problem", and some work has been done with it in the DC Forum and the AHK forum, which - if you've not seen it already - might be of some use/help to you.
Refer IDEA: Super Efficient Extended Hotkey Mapper

As I wrote above, your piece of AHK coding submitted in the OP seems to work for me, so far. I can't see anything amiss with your AHK coding either, and the doubletap seems to be properly catered for, but I'm no expert.

If insoluble, then a useful workaround to your apparent problem might be to use the nifty TapTap app that @mouser wrote, refer:
« Last Edit: May 01, 2017, 10:13 AM by IainB »

jeff_eisenberg

  • Participant
  • Joined in 2017
  • *
  • default avatar
  • Posts: 8
    • View Profile
    • Donate to Member
Re: Help fixing bugs in AutoHotKey SHIFT/SHIFT activate key
« Reply #3 on: May 01, 2017, 11:11 AM »
Thanks. I'll check out the tap tap program. Maybe that will work. I actually got bug 1 fixed with the following code suggested in Stackoverflow. But i still have the problem with bug 2. I'm putting the link to it here:  My issue on StackOverflow

IainB

  • Supporting Member
  • Joined in 2008
  • **
  • Posts: 7,543
  • @Slartibartfarst
    • View Profile
    • Read more about this member.
    • Donate to Member
Re: Help fixing bugs in AutoHotKey SHIFT/SHIFT activate key
« Reply #4 on: May 01, 2017, 12:02 PM »
@jeff_eisenberg: That's interesting. Thanks.
Just out of interest, I used your code, but modified it for doubletap of the ALT key, as below - it works just fine and with no problems (so far!):
~ALT Up:: ; Sense doubletap ALT key
If (A_ThisHotkey == A_PriorHotkey && A_TimeSincePriorHotkey < 400)
{
      Double_ALT := true     ; doubletap ALT key has been detected.
      Sleep, 2000           ; allows time for a action key to be depressed subsequently.
      Double_ALT := false   ; reset if no key depressed inside that time.
}
return

   #If (Double_ALT)       ; Press one of the following  action keys within two seconds after ALT doubletap, to initiate an action.
d::
{
           FormatTime, CurrentDateTime,, yyyy-MM-dd HHmm  ; It will look like 2017-12-21 0353hrs
   SendInput %CurrentDateTime%hrs
           Double_ALT :=false
}
          return
a:: MsgBox, Test "a" key pressed.
s:: MsgBox, Test "s" key pressed.
f:: MsgBox, Test "f" key pressed.
        return   ; Belts-and-braces return.
__________________________________

Could I suggest that you might try similarly (i.e., with doubletap of the ALT key, or similar, rather than the SHIFT key), to establish whether the error behaviour is any different in your case? (Not sure whether you have already tried that.)
It would be interesting if, as and when you do find a fix to your problem, you posted the solution here also.

jeff_eisenberg

  • Participant
  • Joined in 2017
  • *
  • default avatar
  • Posts: 8
    • View Profile
    • Donate to Member
Re: Help fixing bugs in AutoHotKey SHIFT/SHIFT activate key
« Reply #5 on: May 01, 2017, 12:08 PM »
thank you. That's a good suggestion. I'll talk to my boss boss to see if we can do that instead. Shift just seemed like a bigger easier button. The code you have above is not what I'm using. It's modified a little as below....

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}"

~Shift Up::
    Input, key, V L1 t0.5 E, % endKeys
    If (Errorlevel ~= "Shift") {
        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

jeff_eisenberg

  • Participant
  • Joined in 2017
  • *
  • default avatar
  • Posts: 8
    • View Profile
    • Donate to Member
Re: Help fixing bugs in AutoHotKey SHIFT/SHIFT activate key
« Reply #6 on: May 01, 2017, 12:44 PM »
I'm going to try to go with your suggestion.
I replaced "Shift" in the script with "Alt" but that's apparently not sufficient.
Can you give me any guidance or show what needs to be done to convert it from "Shift" to "Alt" ?

IainB

  • Supporting Member
  • Joined in 2008
  • **
  • Posts: 7,543
  • @Slartibartfarst
    • View Profile
    • Read more about this member.
    • Donate to Member
Re: Help fixing bugs in AutoHotKey SHIFT/SHIFT activate key
« Reply #7 on: May 01, 2017, 02:41 PM »
I have now been able to intermittently reproduce the errors similar to your Bug #1, but not yet Bug #2, using the code above for the ALT key. (So, it seems not to matter whether one uses the ALT key or the SHIFT key as the doubletap.)
  • If I type [Alt+f+ALT Alt+f+ALT in succession like that,  repeatedly and at different speeds, it makes a difference:
  • Typing it in succession sometimes outputs "ff", which is an AHK abbreviation hotkey for me, producing "Firefox" (that's how I know "ff" must have been output).
  • If I type it very quickly, then it will sometimes output the "f" test message box.

From this, I at first surmised that what may be happening here is that, due to timing delays/interrupts/collisions (or something) in the keyboard controller, the keys are arriving out of sequence at the buffers for A_ThisHotkey and A_PriorHotkey. I mean, that could be the explanation for Alt+f+ALT --> "ff". However, that probably could not occur unless the keyboard controller were on the blink. More likely is that the "f" is put into and remains in a buffer, and the "ALT" does not, so the next "f" arrives next to the first "f".

Typing Alt+f+ALT Alt+f+ALT repeatedly at speed will occasionally lead to  two ALTs occurring close together (back-back) and within 2 seconds the "f" following, thus creating a match in the A_ThisHotkey and A_PriorHotkey, and the "f" thus triggering a valid action (the Message Box). So it's probably just an accident of event sequence and timing. So it's not a bug.

I suspect that this event sequence and timing accident may be at root of the cause of your Bug #2 also, and that using a different (non-Shift) and little-used doubletap key will avoid/reduce the potential for that particular "bug".

The obvious thing to do would be to put NULLs or (better) odd/different and non-SHIFT/ALT values in A_ThisHotkey and A_PriorHotkey, after setting Double_SHIFT := false (so they then likely would not match next time around, whatever the next key pressed), however, that seems to be something that is not possible in AHK.

Listing all the possible endkeys as per <https://stackoverflow.com/questions/43701593/authohotkey-exclusive-double-tap-shift-followed-by-action-key> would seem to be a really kludgy way of working around this, but maybe there is no more elegant way to work around it.

You could still consider using the TapTap executable, I suppose...

jeff_eisenberg

  • Participant
  • Joined in 2017
  • *
  • default avatar
  • Posts: 8
    • View Profile
    • Donate to Member
Re: Help fixing bugs in AutoHotKey SHIFT/SHIFT activate key
« Reply #8 on: May 01, 2017, 04:36 PM »
Thanks so much. I think you're solution is best. Using "Alt" should make that anomaly a non-issue. Do you know how I can get it to work with the following script? I've replaced "Shift" with "Alt" but can't get it to work.

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}"

~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 Shift 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

IainB

  • Supporting Member
  • Joined in 2008
  • **
  • Posts: 7,543
  • @Slartibartfarst
    • View Profile
    • Read more about this member.
    • Donate to Member
Re: Help fixing bugs in AutoHotKey SHIFT/SHIFT activate key
« Reply #9 on: May 02, 2017, 09:55 AM »
The above code seems to be incomplete/wrong and thus will not work AS-IS.
I have spent quite a bit of time re-writing it and getting it to work, but not being an AHK coder of any great merit, I am having to learn by doing (and using the Help manual).
In the process, I have figured out what needs to be done to stop the errors getting through in the original code sample you had - the input needs to be validated. Though it worked after a fashion, that sample has several errors in, by the way.
At the moment I am stuck at the point where there seems to be a disconnect - I cannot get some AHK input validation routines to work the way the manual says they should, and I haven't had the time to figure out why they won't. I need to become less ignorant about it.
I am going to have to check to see whether I have the latest AHK and matching manual.

So please don't expect me to be of much use in the short term as it is probably very much a case of the blind leading the blind. What's keeping me involved is a desire to help coupled with an instinctive compulsion to solve puzzles - like the one you presented - and I know I will be able to benefit by learning from becoming involved (same way as I am slowly learning Python by helping my daughter in her computer studies).

I am conditioned to think in terms of simple number-crunching, data analysis, financial modelling, linear programming and cross-tabulation using appropriate tools and  sometimesa low-level (assembler) language or something that seems nice and straightforward like FORTRAN, so trying to use a relatively high-level language like Python or the AHK script is hurting my head...    :o

jeff_eisenberg

  • Participant
  • Joined in 2017
  • *
  • default avatar
  • Posts: 8
    • View Profile
    • Donate to Member
Re: Help fixing bugs in AutoHotKey SHIFT/SHIFT activate key
« Reply #10 on: May 02, 2017, 10:06 AM »
Love it. Thanks!
I thought that this approach seemed more stable but I couldn't figure out how to replace it with Alt.
Using Alt, endKeys i don't think would be necessary because no one would ever double tap Alt.
I'm also posting on StackOverflow and will post back here if I get any results.

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

IainB

  • Supporting Member
  • Joined in 2008
  • **
  • Posts: 7,543
  • @Slartibartfarst
    • View Profile
    • Read more about this member.
    • Donate to Member
Re: Help fixing bugs in AutoHotKey SHIFT/SHIFT activate key
« Reply #11 on: May 02, 2017, 10:36 PM »
I thought that this approach seemed more stable but I couldn't figure out how to replace it with Alt.
Using Alt, endKeys i don't think would be necessary because no one would ever double tap Alt.
I'm also posting on StackOverflow and will post back here if I get any results.
-jeff_eisenberg (May 02, 2017, 10:06 AM)

Ergonomics of the UI:
  • Replacing the target TapTap key with another one seems to be (will be) relatively easy.    :up:
  • By the way, the EndKeys thing seems to be an irrelevant diversion, looking at thew process flow. It's all about ergonomics.
  • Getting the rest of the code right seems to be where the problems lie!    :-[
  • More ergonomics: ",,,no one would ever double tap Alt. ..." - actually, I discovered that it can be very frequently used by people (like me) who use Alt+Tab as a window switcher. That keeps triggering the TapTap with invalid keys, so needs to be filtered out such that only "valid" TapTaps are processed. :(

Ath

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 3,627
    • View Profile
    • Donate to Member
Re: Help fixing bugs in AutoHotKey SHIFT/SHIFT activate key
« Reply #12 on: May 03, 2017, 01:32 AM »
it can be very frequently used by people
"Alt" is about the worst key to use for something like this, as it is used for nearly every hotkey in every application, and it has the function of activating hotkey-underscores in the menu of standard 'classic' (Win32/WinForms) Windows UI applications when pressed once.
Only usable keys would probably be "Shift" or the hardly ever used "Scroll Lock".

tomos

  • Charter Member
  • Joined in 2006
  • ***
  • Posts: 11,963
    • View Profile
    • Donate to Member
Re: Help fixing bugs in AutoHotKey SHIFT/SHIFT activate key
« Reply #13 on: May 03, 2017, 03:44 AM »
it can be very frequently used by people
"Alt" is about the worst key to use for something like this, as it is used for nearly every hotkey in every application, and it has the function of activating hotkey-underscores in the menu of standard 'classic' (Win32/WinForms) Windows UI applications when pressed once.

True, I've given up simple Alt+[letter] key shortcuts for that reason: either they dont work, or stop the Alt menu combinations from working.
FWIW
I have/use a good few Alt key shortcuts in combination with another qualifier key (+ letter key) without problem.
Tom

jeff_eisenberg

  • Participant
  • Joined in 2017
  • *
  • default avatar
  • Posts: 8
    • View Profile
    • Donate to Member
Re: Help fixing bugs in AutoHotKey SHIFT/SHIFT activate key
« Reply #14 on: May 03, 2017, 09:59 AM »
Thanks for the feedback. Yea, we just wanted to find a universal "activator" for the company so that when following it by any letter, it would trigger different macros. Everything we try seems to have some kind of conflict. We wanted to use one that would be easy like SHIFT/SHIFT... But i guest it's not that easy. Recommendations appreciated.

jeff_eisenberg

  • Participant
  • Joined in 2017
  • *
  • default avatar
  • Posts: 8
    • View Profile
    • Donate to Member
Re: Help fixing bugs in AutoHotKey SHIFT/SHIFT activate key
« Reply #15 on: May 04, 2017, 10:12 AM »
If anyone is interested. Here's the script I got for using double tap Alt.
Seems to be working with no conflicts so far

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)
    a:: MsgBox, Test a
    b:: MsgBox, Test b
    c:: MsgBox, Test c
    d::
    FormatTime, CurrentDateTime,,MM/dd/yy - hh:mmtt
    SendInput %CurrentDateTime%
            Double_ALT :=false
return
return

cranioscopical

  • Friend of the Site
  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 4,776
    • View Profile
    • Donate to Member
Re: Help fixing bugs in AutoHotKey SHIFT/SHIFT activate key
« Reply #16 on: May 04, 2017, 01:47 PM »
Thanks for posting, it's often handy to have something saved and ready to use/adapt.  :Thmbsup: