Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Strange SHIFT spamming in simple script


  • Please log in to reply
1 reply to this topic
GeneralScott
  • New members
  • 1 posts
  • Last active: Oct 07 2015 11:23 PM
  • Joined: 07 Oct 2015

Hi, I'm trying to make a super-basic script to make one of my mouse buttons toggle the key L in order to turn a regular flashlight in a tactical shooter into a strobe light. It works, but it has a major issue, which I will explain in a moment.

 

 

#MaxThreadsPerHotkey 2

$*~XButton2:: ;mousebutton 2 to toggle
t := !t
while t
     {
    Send p ;toggle flashlight
    sleep 75 ;75 ms between flashes
    }
        
return

 

 

The problem is that this script also spams other keys (shift, control, windows, or alt) under certain circumstances. If I just press mousebutton2, everything works as intended. However, if I hold down shift while the "p" spam is activated, the script begins to spam both "p" and shift. This only occurs with the shift, control, windows, or alt keys (I can hold down any regular key with no problems.)

 

This causes me to be unable to do things like crouch, sprint, etc. ingame while using this script, so it's pretty major. I've messed around with this for a couple hours but as you can probably tell I have no idea what the problem is so I figured someone else might.

 

Thanks a lot for the help!



Shadowpheonix
  • Members
  • 268 posts
  • Last active:
  • Joined: 10 Feb 2014

This is actually expected behavior.  If you are holding down a modifier key (such as Shift or Alt) when the SEND command is run, that modifier key will affect the output of the SEND command.  You might be able to work around this with something like the following (untested, and likely not optimal)...

#MaxThreadsPerHotkey 2
$*~XButton2:: ;mousebutton 2 to toggle
t := !t
while t
     {
    ShiftState := GetKeyState("Shift", "P")
    AltState := GetKeyState("Alt", "P")
    LWinState := GetKeyState("LWin", "P")
    RWinState := GetKeyState("RWin", "P")
    CtrlState := GetKeyState("Ctrl", "P")
    Send {Shift Up}{Alt Up}{Ctrl Up}{Win Up}p ;toggle flashlight
    If ShiftState
        Send {Shift Down}
    If AltState
        Send {Alt Down}
    If CtrlState
        Send {Ctrl Down}
    If LWinState
        Send {LWin Down}
    If RWinState
        Send {RWin Down}
    sleep 75 ;75 ms between flashes
    }
       
return