AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Help with a toggle key on/off script

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
mrTesting
Guest





PostPosted: Thu Jul 24, 2008 5:14 am    Post subject: Help with a toggle key on/off script Reply with quote

Hi, I'm having some trouble with this script.

Code:


$*space::
Loop
{
GetKeyState, state, space, P
if state=U
{
return
}
{
Send {space}
Sleep 500
}
}
return



What I would like for the script to do, is for the duration of me holding down space, it would hold space for 500 milliseconds, then turn it off for 500 milliseconds, then on for 500 milliseconds, etc.

Instead this seems to quickly tap space then hold for 500 milliseconds.

How can I create a script that specifies not just the wait time beteween the button presses, but also how long the button presses are?

Thanks for your help
Back to top
Krogdor



Joined: 18 Apr 2008
Posts: 908
Location: The Interwebs

PostPosted: Thu Jul 24, 2008 5:21 am    Post subject: Reply with quote

Code:


$*space::
Loop
{
  GetKeyState, state, space, P
  if state=U
  {
  return
  } 
  Send % "{space " (Mod(A_Index,2) ? "down}" : "up}") 
  Sleep 500
}
Send {Space up} ;to prevent space sticking down
return
Back to top
View user's profile Send private message AIM Address
mrTesting
Guest





PostPosted: Thu Jul 24, 2008 2:25 pm    Post subject: Reply with quote

Hi Krogdor,

thanks for your reply

The script that you posted is closer to what I would want. I have 2 questions though.

Is there a way for me to specify different times for key down and key up?

ie

while holding the space bar down, I get the result

space down 500 milliseconds

space up 300 milliseconds

space down 400 milliseconds

space up 200 milliseconds

and then loop those 4 over and over?

2. This loop appears to override all other keys I press. Is there a way I can get this to play nicely so that other button presses I make while holding down the space bar will still function as normal?
Back to top
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group