 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
Kramit Guest
|
Posted: Wed Jun 04, 2008 12:29 am Post subject: Space bar performs different task with each successive press |
|
|
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
|
Posted: Wed Jun 04, 2008 2:55 am Post subject: |
|
|
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 |
|
 |
[VxE]
Joined: 07 Oct 2006 Posts: 1494
|
Posted: Wed Jun 04, 2008 3:23 am Post subject: |
|
|
| 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 |
|
 |
Lexikos
Joined: 17 Oct 2006 Posts: 2737 Location: Australia, Qld
|
Posted: Wed Jun 04, 2008 11:44 am Post subject: |
|
|
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 |
|
 |
greynite
Joined: 17 May 2008 Posts: 11
|
Posted: Wed Jun 04, 2008 3:04 pm Post subject: |
|
|
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 |
|
 |
Kramit Guest
|
Posted: Fri Jun 06, 2008 2:01 am Post subject: |
|
|
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
|
Posted: Fri Jun 06, 2008 2:10 am Post subject: |
|
|
| 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 |
|
 |
engunneer
Joined: 30 Aug 2005 Posts: 6847 Location: Pacific Northwest, US
|
Posted: Fri Jun 06, 2008 2:06 pm Post subject: |
|
|
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 |
|
 |
Wee Dawg
Joined: 28 Jun 2008 Posts: 13 Location: Kentucky
|
Posted: Sat Jun 28, 2008 9:32 pm Post subject: Can you add a timer to go back to one? |
|
|
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 |
|
 |
[VxE]
Joined: 07 Oct 2006 Posts: 1494
|
Posted: Sun Jun 29, 2008 12:45 am Post subject: Re: Can you add a timer to go back to one? |
|
|
| 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 |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|