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

<< < (2/4) > >>

jeff_eisenberg:
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:
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:
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:
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:
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

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version