0

Let me explain my scenario.

I'm holding down the 1 key producing a string of 1's. When I right or left click my mouse, the string of 1's stop briefly before resuming once again to produce a string of 1's inputs. The 1 key has been pressed and held down once throughout this.

The problem occurs when I remap the left and right mouse clicks to a key on the keyboard; this is what happens.

I'm once again holding down the 1 key producing a string of 1's. When I press the remapped key the string of 1's stop and the mouse left / right clicks as intended, however, once I release the remapped key the string of 1's do not continue like in the first scenario. This means that I would have to repress and hold the 1 key in order to start the string of 1's again.

Question: How do I remap the mouse clicks to a key so that the string of 1's continues afterwards once I release the remapped key?

0

In AutoHotKey you would need to poll the keys that are down when you release your remapped key then re-press it virtually.

Two versions, one simple, one complex:

Simple version checks for keys that are physically down on release and just re-presses them

keysOfInterest := ["a","b","c",...]    ; list of keys

LButton::
  ; Do a thing
return

LButton Up::
  ; Do an un-thing
  for index, element in keysOfInterest
  {
    if GetKeyState(element,"P") ; key is physically down.
      SendInput {%element% up}{%element% down}; re-press it
  }
return

Complex version that tracks if a key was physically down BEFORE your remapped key got pressed. If it was pressed during your remap press, it doesn't react.

keysOfInterest := ["a","b","c",...]    ; list of keys
keyTrackOne   := [0,0,0,...]          ; track their state at key-down

LButton:: ; Key-down
  for index, element in keysOfInterest ; cycle through keys of interest
  {
    if GetKeyState(element,"P")       ; key is currently down
      keyTrackOne[index] := 1         ; mark it as 
  }
  ; Do a thing
return

LButton up::
  for index, element in keyTrackOne
  {
    if (element == 1) && GetKeyState(keysOfInterest[index],"P")
      SendInput {%keysOfInterest[index]% Up}{%keysOfInterest[index]% Down}; re-press it
  }
  ; Do an un-thing
return
  • See my comment, it wouldn't let me post the script in the comment. – jameslacey01 May 6 at 10:28
  • I'm finding that the string of 1's do not continue with the first example, it only adds 1 extra 1 at the end instead of keeping it held down. – jameslacey01 May 6 at 10:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.