Jump to content


Toggle interval keypress


  • Please log in to reply
4 replies to this topic

#1 Tsurany

Tsurany
  • Guests

Posted 07 May 2012 - 01:49 PM

Hi,

I have the following script:
F1::
  alt := not alt
  If (alt)
  {
    MouseClick Left, , , , , D
 MouseClick Right, , , , , D
  }
  Else
  {
MouseClick Right, , , , , U
    MouseClick Left, , , , , U
 
  }
Return
Pressing F1 will keep both mousekeys down and pressing F1 again will lift them. To this I want to add an action that will also press '3' every 4 seconds, what addition should I use? I find a lot of loop scripts that require me to keep pressing the key but I don't want that, it must remain toggable.

Can anyone point me in de right direction?

Regards,

#2 dmg

dmg
  • Members
  • 1736 posts

Posted 07 May 2012 - 02:18 PM

I think you will like the SetTimer command.

#3 Tsurany

Tsurany
  • Guests

Posted 07 May 2012 - 02:34 PM

So if I create the following timer it should work?

SetTimer, Press , 4000

Then I only need a statement for pressing '3'.

I also found the following:

delaybetweenfkeys:=2
fkeydowndelay:=37

F1::
   loop
   {
      if checkkeyreleased(A_thishotkey)   ; a_thishotkey is a built in variable
         break                             ; that stores whatever the last key pressed was
      presskey("Enter")                       ; which of course will be F1
   }
return

presskey(key,del1 =999999, del2 =999999) ;you cant set variables as default parameters in functions
{                                        ; so this is a way around it
   global delaybetweenfkeys,fkeydowndelay
   del1:=del1=999999 ? fkeydowndelay : del1  ;default value will be value of 'fkeydowndelay' 
   del2:=del2=999999 ? delaybetweenfkeys : del2 ;default value will be value of 'delaybetweenfkeys' 
   sendinput {%key% down}                ;press the key down
   sleep %del1%                         ;hold for this delay
   sendinput {%key% up}                  ;release key
   sleep %del2%                         ; for this delay
return
}


checkkeyreleased(key,checkdelay =2)
{
   
     Sleep, %checkdelay%               ;tiny delay to give computer a chance to see if key is down 
   GetKeyState, state, %key%, P         ;stores the state of the key to variable 'state'
   if state = U  ; The key has been released, so break out of the loop.      
       return true
   else
      return false
}

But I don't know how to adapt it to my situation.

#4 engunneer

engunneer
  • Fellows
  • 9162 posts

Posted 07 May 2012 - 02:44 PM

you are getting there with the settimer command. I don't think you need that other script

the settimer command calls a label, so you need to make a label called "Press" for it to call.

inside (after) the label you can put code for what you want to happen. The Send command can send a '3'
at the end of your labeled subroutine, don't forget Return!

#5 Tsurany3

Tsurany3
  • Guests

Posted 09 May 2012 - 07:27 PM

This is what I made, works good. Thnx for the help :D

F1::
  alt := not alt
  If (alt)
  {
SetTimer, Press, 4500
    MouseClick Left, , , , , D
Press:
Send 3
return
  }
  Else
  {
SetTimer, Press, Off
    MouseClick Left, , , , , U
Send RButton
 
  }
Return