Jump to content

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

help held down space key won't work but toggle works



  • Please log in to reply
5 replies to this topic
lunamanx
  • New members
  • 4 posts
  • Last active: Mar 23 2016 03:50 AM
  • Joined: 03 Oct 2015
Made this script to toggle for spamming keys.  Now I want to change it to pressed down instead of toggle. 
 
space::
L++
IF L = 1
{
SetTimer, key1, 3000
SetTimer, key2, 500
SetTimer, key3, 10
L = 3
}
IF L = 4
{
SetTimer, key1, off
SetTimer, key2, off
SetTimer, key3, off
L = 0
}
return
 
Key1:
{
send, {1}
send, {1}
sleep, 10
}
return
 
key2:
{
send, {2}
send, {2}
sleep, 10
}
return
 
key3:
{
sleep, 100
send, {shift down}
mouseclick
send, {shift up}
sleep, 100
}
return
 
F2::
exitapp
 
 
using GetKeyState and I can't get it to work.  Someone help please???
 
$space::
while GetKeyState("space" , "P")
{L++
IF L = 1
{
SetTimer, key1, 3000
SetTimer, key2, 500
SetTimer, key3, 10
L = 3
}
.
.
.
 
 
 
 
 
 


boiler
  • Members
  • 252 posts
  • Last active: Nov 07 2015 09:39 PM
  • Joined: 04 Jun 2014

If I understand what you're trying to do, this should work:
 

$space::
	SetTimer, key1, 3000
	SetTimer, key2, 500
	SetTimer, key3, 10
	KeyWait, Space
	SetTimer, key1, Off
	SetTimer, key2, Off
	SetTimer, key3, Off
return


lunamanx
  • New members
  • 4 posts
  • Last active: Mar 23 2016 03:50 AM
  • Joined: 03 Oct 2015

Thank you Boiler,

It's working perfectly, so that's on a loop and checking for key status every loop?  If so, can't keywait be at the end?  

 

Or is it waiting so that it can proceed to next commands?

 

I'm trying to understand it.  Thanks again.



boiler
  • Members
  • 252 posts
  • Last active: Nov 07 2015 09:39 PM
  • Joined: 04 Jun 2014
It's not a loop. It executes the SetTimer commands, which causes those routines to automatically be executed as often as is specified by each of the SetTimer commands, and they will continue to do so until they are turned off. KeyWait will cause it to wait right there until you release the space bar, after which it executes the commands to turn off the SetTimer routines from being executed. Then it does nothing until you press the space bar again, which will cause it to start from the beginning.

KeyWait cannot be at the end. If it was, it would turn off the SetTimer routines immediately after turning them on, so they won't continue to execute.

Exaskryz
  • Members
  • 3249 posts
  • Last active: Nov 20 2015 05:30 AM
  • Joined: 23 Aug 2012

Boiler gave you a great answer. But I'd like to instruct you as to how your GetKeyState attempt was flawed. It wasn't a problem with GetKeyState, but with variable control.

 

 


$space::
while GetKeyState("space" , "P")
{L++
IF L = 1
{
SetTimer, key1, 3000
SetTimer, key2, 500
SetTimer, key3, 10
L = 3
}

 

Gosh dang this forum and deleting the words after a manual quote is embedded....

 

This approach would work, but is needlessly long, if you do this:

 

$space::
While GetKeyState("Space","P")
{
L++
If L=1
{
SetTimer, key1, 3000
SetTimer, key2, 500
SetTimer, key3, 10
L = 3
}
}
L:=0
SetTimer, key1, Off
SetTimer, key2, Off
SetTimer, key3, Off
return

 

But this needlessly increases the value of L very rapidly. L=1 will only be true when you start the script. L++ is being increased to values that for all intents and purposes are only >1 to us. So we're taking time to increase the variable for no purpose. Additionally, that could make the SetTimers not capable of interrupting, though I haven't tested it. Usually I add a Sleep function where I will allow a script to be interrupted.



lunamanx
  • New members
  • 4 posts
  • Last active: Mar 23 2016 03:50 AM
  • Joined: 03 Oct 2015
✓  Best Answer

wow!! Thank you both for excellent explanation.