Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stuck Shift key on successive keystrokes #47

Open
FordeD opened this issue Sep 28, 2019 · 1 comment
Open

Stuck Shift key on successive keystrokes #47

FordeD opened this issue Sep 28, 2019 · 1 comment

Comments

@FordeD
Copy link

FordeD commented Sep 28, 2019

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
Copy link
Owner

evilC commented Sep 28, 2019

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
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants