evilC / AutoHotInterception

An AutoHotkey wrapper for the Interception driver
MIT License
708 stars 64 forks source link

Stuck Shift key on successive keystrokes #47

Open FordeD opened 4 years ago

FordeD commented 4 years ago
pressButtons(sKey, sflag) {
    keys := StrSplit(sKey, "")
    if (sflag == "Up") {
      keys := ReverseArray(keys)
    }
    for i, k in keys {
      key := k
      if (key == "^") {
        StringReplace, key, key, ^, Ctrl
      }
      if (key == "!") {
        StringReplace, key, key, !, Alt
      }
      if (key == "+") {
        StringReplace, key, key, +, Shift
      }
      if (key == "#") {
        StringReplace, key, key, #, Win
      }
      if (key == A_Space) {
        StringReplace, key, key, %A_Space%, Space
      }
      AHI.SendKeyEvent(KEYBOARD, GetKeySC(key), sflag == "Down" ? 1 : 2)
    }
}

sKey = "+a" sflag = "Down"\"Up" I catch a bug in press Shift(press) -> a(press) -> a(release) -> Shift(release) Shift button Stucked after Why?

evilC commented 4 years ago

AHI.SendKeyEvent(KEYBOARD, GetKeySC(key), sflag == "Down" ? 1 : 2)
Press is 1, release is 0. 2 will do nothing.
So you will only ever press the key, and never release it
Also, this is inefficient:

      if (key == "!") {
        StringReplace, key, key, !, Alt
      }
      if (key == "+") {
        StringReplace, key, key, +, Shift
      }

Use else if

      if (key == "!") {
        StringReplace, key, key, !, Alt
      }
      else if if (key == "+") {
        StringReplace, key, key, +, Shift
      }

key will only ever be one of these values, it's pointless to check them all
I also probably would not bother reversing the array, it's computationally quite expensive, just iterate the keys array forward or backward depending on the value of sFlag

if (sFlag == "Up"){
   i := 1
   order := 1
}
else
{
   i := keys.Length()
   order := -1
}
Loop % keys.Length {
    key := keys[i]
    ; Do IF checks here
    i += order
}