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 

Increment question

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





PostPosted: Sat Jan 09, 2010 5:51 pm    Post subject: Increment question Reply with quote

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

PostPosted: Sat Jan 09, 2010 6:04 pm    Post subject: Reply with quote

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
View user's profile Send private message
Zaw
Guest





PostPosted: Sat Jan 09, 2010 6:13 pm    Post subject: Reply with quote

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

PostPosted: Sat Jan 09, 2010 6:37 pm    Post subject: Reply with quote

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
View user's profile Send private message
zaw
Guest





PostPosted: Sat Jan 09, 2010 7:04 pm    Post subject: Reply with quote

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
Display posts from previous:   
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