AutoHotkey Community

It is currently May 26th, 2012, 3:44 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 9 posts ] 
Author Message
PostPosted: April 3rd, 2009, 4:17 pm 
Offline

Joined: March 30th, 2009, 7:17 pm
Posts: 9
Hello All I appreciate anyone's time in helping me with this problem.

I'm trying to obtain a method of using 1 key to turn on part of a script. I have come up with this, only the script seems to ignore the hot key requirement to execute the break command and just Breaks automatically.

any help would be helpful. I am simply to trying to toggle on/off a loop.

Code:
#InstallKeybdHook


~F12 up::                       
Goto, gather

   gather:
      {
      Loop
      {
      goto Action
      If IsKeyPressed("F12")
      Send, {+end}
      Break
      }
      }
   Return

      IsKeyPressed(v_KeyName)
      {
      GetKeyState, state, %v_KeyName%, P
      If state = D  ; The key has been pressed
      {
      Return 1
      }
      Return 0
      }

Action:
soundbeep 250
Loop 25
{
        sleep 500
      Soundbeep 50
      MouseClick, left ; Swing
      Sleep, 10200 ;waits for 10.2 seconds
+end:: Break
}
return


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 4th, 2009, 1:07 pm 
Offline

Joined: February 7th, 2008, 9:48 pm
Posts: 509
maybe useful to get some ideas how to break a loop with hotkey (F2):

instead of goto use gosub it makes it more readable and easier to follow the structure :)

Code:
F1::
Status=0
Gosub StartLoop
return

F2::
Status:= !Status  ; toggles value of Status between 1 and 0 to break the loop
return


StartLoop:
loop 100
{
If Status=1
break
Gosub MakeSomeNoise
}
return

MakeSomeNoise:
SoundBeep 250
sleep 200
return

!ESC::
ExitApp
return


Last edited by closed on April 4th, 2009, 4:28 pm, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 4th, 2009, 1:52 pm 
There are so many problems (logic/stucture errors) with that code, I cannot tell what you are trying to accomplish. How about a detailed descriton of what you want to do?


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: April 6th, 2009, 12:37 am 
Offline

Joined: March 30th, 2009, 7:17 pm
Posts: 9
All I am trying to have the Script do is

Code:
soundbeep 250
Loop
Sleep 500
Soundbeep 50
MouseClick, left
Sleep, 10200


when I press a button, and stop when i press the same button really.

I like the status idea. might try give that a whirl.

Thanks for you replies either way. I am learning, and like to find new ways of doing things.

Regards
Ore\


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 25th, 2009, 6:35 pm 
Offline

Joined: March 30th, 2009, 7:17 pm
Posts: 9
anyone anything?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 25th, 2009, 8:16 pm 
Offline

Joined: February 7th, 2008, 9:48 pm
Posts: 509
Code:
#Persistent
SetTimer,getstatus,250
return

F1::
status:=!status
return

getstatus:
If status=1
gosub MakeNoise
return

MakeNoise:
soundbeep 250
Loop 25
{
If Status=0
Break
sleep 500
Soundbeep 50
MouseClick, left
}
Loop 10   ;so you can break during the 10200ms wait
{
If status=0
break
sleep 1020
}

return
!ESC::
ExitApp


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 26th, 2009, 8:23 am 
i have same problem but my script is pretty much bigger;] i wanted to be able to break the loops at any time during it's execution i tried to put
Code:
if GetKeyState("t", "P")
break

after eaach command .... it works but made script you know full of it does anybody know other way to break loops with only few lines not on whole script


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: April 26th, 2009, 11:11 am 
Offline

Joined: February 7th, 2008, 9:48 pm
Posts: 509
maybe take a look at Lexicon's version of autohotkey ( i have not tried it but will do now :D ):


http://www.autohotkey.net/~Lexikos/AutoHotkey_L/

it has a while expression command in it

Code:
while GetKeyState("LButton")
    {
        MouseGetPos, x, y
        ToolTip, % begin_x ", " begin_y "`n" Abs(begin_x-x) " x " Abs(begin_y-y)
        Sleep, 10
    }


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 26th, 2009, 7:56 pm 
Offline

Joined: December 27th, 2007, 12:59 pm
Posts: 25
Location: Brazil
Ore Aird wrote:
All I am trying to have the Script do is

Code:
soundbeep 250
Loop
Sleep 500
Soundbeep 50
MouseClick, left
Sleep, 10200


when I press a button, and stop when i press the same button really.

I like the status idea. might try give that a whirl.


I am sure tha not got what You want exactly, but try understand this logic to can, I hope, does the changes You need.
Code:
#Persistent
#SingleInstance
Process, Priority, , N
SetBatchLines, -1


F12::
If ( Status = 1 )
  {
   Status := 0
   GoTo, Stop
  }
Else
  {
   Status := 1
   Counter := 0
   GoTo, Action
  }
Return


Action:
ToolTip, Initiated !`nStatus = %Status%`nCouter = %Counter% ; To tests, can delet after
Soundbeep 250
Sleep, 500   ;Seems very short, I hear only one beep. With 1500 play 2 beeps.
Counter += 1
If ( Status = 0 or Counter = 25)
  GoTo, Stop
Soundbeep 50
MouseClick, left
SetTimer, Action102s, 10200
Return


Action102s:
SetTimer, Action102s, Off
If ( Status = 0 )
 GoTo, Stop
;Here you put what you desire Action102s does each 10.2 seconds.
GoTo, Action  ; like this
Return

   
Stop:
SetTimer, Action102s, Off
Status = 0
Counter = 0
ToolTip, Stoped !`nStatus = %Status%`nCouter = %Counter% ; To tests, can delet after
Sleep, 2000 ; To tests, can delet after
ToolTip,  ; To tests, can delet after
Return


Note that the second Key command don't function if the script is running a loop, if there are some way to do this, someone more expert could explaine how, I can't. I think that any looping must end before hot keys turn reliable, by this I didn't used Loopings.

_________________
The humanity is the Evolution taking consciousness about itself.


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: BrandonHotkey, Exabot [Bot], notsoobvious, Yahoo [Bot] and 13 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group