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 

Space bar performs different task with each successive press

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





PostPosted: Wed Jun 04, 2008 12:29 am    Post subject: Space bar performs different task with each successive press Reply with quote

I'm looking for help with a small script, that will do the following:

1. Press space bar once,
Mouse click certain part of screen. I know this can be done.
2. Press space bar once,
click on dialog box, again I know this can be done.
3. Press space bar once,
Mouse click certain part of screen. I know this can be done.
4. Press space bar once,
click on dialog box, again I know this can be done.
5. Press nothing after step 4, restarts from the top, waiting for the space bar be pressed again.

The trouble I'm having is not knowing if Autohotkey can work in sequence, kinda like stepping through a plc program. The same button will perform each step with the single key press. Any help would be appreciated.
Back to top
PurloinedHeart



Joined: 04 Apr 2008
Posts: 209
Location: Canada

PostPosted: Wed Jun 04, 2008 2:55 am    Post subject: Reply with quote

Many different ways of doing this, if I interpreted it correctly. Easiest way is to do something like..

Code:

Count := 0

SpaceBar::
Count++
If (Count = 1)
  Do this
else if (Count = 2)
  Do this other things
...
Back to top
View user's profile Send private message
[VxE]



Joined: 07 Oct 2006
Posts: 1494

PostPosted: Wed Jun 04, 2008 3:23 am    Post subject: Reply with quote

Code:
*space::
sSwitch := Mod( 0 sSwitch, 4 ) + 1
If ( sSwitch = 1)
   msgbox The first thing
If ( sSwitch = 2 )
   msgbox The second thing
If ( sSwitch = 3 )
   msgbox The third thing
If ( sSwitch = 4 )
   msgbox The fourth thing
return

tested.
_________________
My Home Thread
More Common Answers: [1]. It's in the FAQ [2]. Ternary ( a ? b : c ) guide [3]. Post code inside [code][/code] tags !
Back to top
View user's profile Send private message
Lexikos



Joined: 17 Oct 2006
Posts: 2737
Location: Australia, Qld

PostPosted: Wed Jun 04, 2008 11:44 am    Post subject: Reply with quote

Yet another approach.
Code:
Hotkey, Space, First
return

First:
    MsgBox First task.
    Hotkey, Space, Second
return

Second:
    MsgBox Second task.
    Hotkey, Space, Third
return

Third:
    MsgBox Third task.
    Hotkey, Space, Fourth
return

Fourth:
    MsgBox Fourth task.
    Hotkey, Space, First
return
Back to top
View user's profile Send private message
greynite



Joined: 17 May 2008
Posts: 11

PostPosted: Wed Jun 04, 2008 3:04 pm    Post subject: Reply with quote

I'd go with [VxE]'s method, and add you should check your environment is what you think it is rather than assuming the [next] action is correct.

Better yet, why not use WinWait etc. to coordinate all 4 steps triggered off one hotkey?

Cheers,
Shawn
Back to top
View user's profile Send private message
Kramit
Guest





PostPosted: Fri Jun 06, 2008 2:01 am    Post subject: Reply with quote

Thats awesome, now here is the code. I don't understand how to set this up to absolute cordinates. It works but not correctly.

Code:

*space::
sSwitch := Mod( 0 sSwitch, 4 ) + 1
If ( sSwitch = 1)
  CoordMode, ToolTip, Screen
   
   MouseClick, left,  194,  180, screen
If ( sSwitch = 2 )
   MouseClick, left,  505,  24
If ( sSwitch = 3 )
   MouseClick, left,  663,  94
If ( sSwitch = 4 )
   MouseClick, left,  660,  19
return
Back to top
[VxE]



Joined: 07 Oct 2006
Posts: 1494

PostPosted: Fri Jun 06, 2008 2:10 am    Post subject: Reply with quote

Kramit should have used [code][/code] tags when he wrote:
Thats awesome, now here is the code. I don't understand how to set this up to absolute cordinates. It works but not correctly.


Code:
*space::
  CoordMode, mouse, Screen
sSwitch := Mod( 0 sSwitch, 4 ) + 1
If ( sSwitch = 1)
   MouseClick, left,  194,  180
If ( sSwitch = 2 )
   MouseClick, left,  505,  24
If ( sSwitch = 3 )
   MouseClick, left,  663,  94
If ( sSwitch = 4 )
   MouseClick, left,  660,  19
return

The number in red is the maximum value for the switch.
_________________
My Home Thread
More Common Answers: [1]. It's in the FAQ [2]. Ternary ( a ? b : c ) guide [3]. Post code inside [code][/code] tags !
Back to top
View user's profile Send private message
engunneer



Joined: 30 Aug 2005
Posts: 6847
Location: Pacific Northwest, US

PostPosted: Fri Jun 06, 2008 2:06 pm    Post subject: Reply with quote

I added code tags to his post.

It looks like he should also read the section in the manual about code blocks (Having more than one statement under an If, for example)
_________________
Unless otherwise noted, all code is untested.
Common Answers: 1.(Loops, Viruses, etc.) 2. Search 3.RTFM
Back to top
View user's profile Send private message Visit poster's website
Wee Dawg



Joined: 28 Jun 2008
Posts: 13
Location: Kentucky

PostPosted: Sat Jun 28, 2008 9:32 pm    Post subject: Can you add a timer to go back to one? Reply with quote

I like VxE's script, I pretty sure its possible, how could I make his script do this aswell?

Click (anykey) once say "This"
If Click a 2nd time within 5 minutes do "This", otherwise go back to First click and start over????
Back to top
View user's profile Send private message
[VxE]



Joined: 07 Oct 2006
Posts: 1494

PostPosted: Sun Jun 29, 2008 12:45 am    Post subject: Re: Can you add a timer to go back to one? Reply with quote

Wee Dawg wrote:
If Click a 2nd time within 5 minutes do "This", otherwise go back to First click and start over????
Code:
*space::
B_TimeSinceThisPriorHotkey := (-oba)+(oba := A_TickCount) ; note: order of operations trick
  CoordMode, mouse, Screen ;               M*SS*ms
sSwitch := ( B_TimeSinceThisPriorHotkey < 5*60*1000) * Mod( 0 sSwitch, 4 ) + 1
If ( sSwitch = 1)
   MouseClick, left,  194,  180 ; or do/send whatever
If ( sSwitch = 2 )
   MouseClick, left,  505,  24
If ( sSwitch = 3 )
   MouseClick, left,  663,  94
If ( sSwitch = 4 )
   MouseClick, left,  660,  19
return

Here's one way to make it reset to '1' after a certain amount of time.
_________________
My Home Thread
More Common Answers: [1]. It's in the FAQ [2]. Ternary ( a ? b : c ) guide [3]. Post code inside [code][/code] tags !
Back to top
View user's profile Send private message
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