| View previous topic :: View next topic |
| Author |
Message |
Zaw Guest
|
Posted: Sat Jan 09, 2010 5:51 pm Post subject: Increment question |
|
|
Hello,
Im making a script than when i press, say F1, a variable goes up by 1 (starting at 0) until it hits 2 (so i presed f1 three times) then goes back to one.
I can then do what i need with keystrokes and stuff from using the variable (1 makes a mouse click at these coordinates, 2 makes it do slightly different ect ect ect)
| Code: | numb=0
tempvar=0
$F1::
if GetKeyState("F1", "P")
{
MsgBox %numb%
tempvar=%numb%
numb:=%tempvar%+1
}
return
|
This is what i have so far. When i press F1 the first time, it shows 0, then a second time it shows 1 and then it is blank until i reload the script.
Any fix for that?
Also, this should take care of resetting numb to 0, right?
| Code: | If (numb=2){
numb=0
} |
Thanks,
~Zaw |
|
| Back to top |
|
 |
Fry
Joined: 01 Nov 2007 Posts: 885
|
Posted: Sat Jan 09, 2010 6:04 pm Post subject: |
|
|
Just a general coding tip.
Upon hitting F1, the hotkey is fired, so no need for GetKeyState, because the hotkey would not fire without F1 being pressed.
| Code: | $F1::
MsgBox %numb%
tempvar=%numb%
numb:=%tempvar%+1
return |
|
|
| Back to top |
|
 |
Zaw Guest
|
Posted: Sat Jan 09, 2010 6:13 pm Post subject: |
|
|
| Fry wrote: | Just a general coding tip.
Upon hitting F1, the hotkey is fired, so no need for GetKeyState, because the hotkey would not fire without F1 being pressed.
| Code: | $F1::
MsgBox %numb%
tempvar=%numb%
numb:=%tempvar%+1
return |
|
Thanks! Still have the problem though ;( |
|
| Back to top |
|
 |
None
Joined: 28 Nov 2009 Posts: 3086
|
Posted: Sat Jan 09, 2010 6:37 pm Post subject: |
|
|
| Code: | State:=0
z::
If State = 0
{
State = 1
Send A
Return
}
If State = 1
{
State = 2
Send B
}
Else
{
State = 0
Send C
}
Return |
This code sends ABCABC with presses of z. With only three this is probably the easiest way to do it. |
|
| Back to top |
|
 |
zaw Guest
|
Posted: Sat Jan 09, 2010 7:04 pm Post subject: |
|
|
| None wrote: | | Code: | State:=0
z::
If State = 0
{
State = 1
Send A
Return
}
If State = 1
{
State = 2
Send B
}
Else
{
State = 0
Send C
}
Return |
This code sends ABCABC with presses of z. With only three this is probably the easiest way to do it. |
Thanks, it works!
Thread can be closed |
|
| Back to top |
|
 |
|