ATTENTION: You are viewing a page formatted for mobile devices; to view the full web page, click HERE.

Other Software > Developer's Corner

Help fixing bugs in AutoHotKey SHIFT/SHIFT activate key

(1/4) > >>

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.


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

; Press a key within two seconds after double tapping the Shift key, to activate an action:
#If (Double_SHIFT)
    FormatTime, CurrentDateTime,,MM/dd/yy - hh:mmtt
    SendInput %CurrentDateTime%
            Double_SHIFT :=false
    a:: MsgBox, Test
    s:: MsgBox, Test
    f:: MsgBox, Test

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.

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:

* TapTap Hotkey Extender forum page
* TapTap - LATEST VERSION INFO THREAD - v1.03.01 - Nov 21, 2006

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

@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.

   #If (Double_ALT)       ; Press one of the following  action keys within two seconds after ALT doubletap, to initiate an action.
           FormatTime, CurrentDateTime,, yyyy-MM-dd HHmm  ; It will look like 2017-12-21 0353hrs
   SendInput %CurrentDateTime%hrs
           Double_ALT :=false
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.


[0] Message Index

[#] Next page

Go to full version