AutoHotkey Community

It is currently May 26th, 2012, 8:29 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 8 posts ] 
Author Message
PostPosted: August 20th, 2009, 12:09 am 
Offline

Joined: August 18th, 2009, 11:08 pm
Posts: 5
I want to create a variable speed FastForward with a Hotkey sending Skips. Below test scripts explaining my problem in achieving that goal:

In the script below, when I type 3 it starts sending f at low speed, then when I press 2 I go to speed 2, then again to speed 3, then again to speed 0.

Code:
SetTitleMatchMode, 2
DetectHiddenText, On
#NoEnv
#Persistent
SendMode Input

#IfWinActive Notepad
Stop = 0      
3:: FFW()
2::
Stop := stop + 1
if stop > 3
   stop = 0
return


FFW()
{
Global stop = 1
   Loop 400
   {
   SplashTextoff
   SplashTextOn,200,50,Speed, %stop%
   Send f
   if stop = 0
      break
   if Stop = 1
      Sleep 500
   if stop = 2
      sleep 150
   if stop = 3
      sleep 50
   
   }
}


This is the functionnality I want, except that I would like to do that by sucessive press of the 3 key instead of using the 3 key to start and the 2 key to change speed.
press 3 starts sending f at speed 1
press 3 again, go to speed 2
press 3 again, go to speed 3
press 3 again, stop

Unfortunately, I cannot get that to work, as it seems that as long as the loop (trigerred by the 3 press) is running, It does not interpret furher key presses of 3.
I tried this without sucess:

Code:
SetTitleMatchMode, 2
DetectHiddenText, On
#NoEnv
#Persistent
SendMode Input

#IfWinActive Notepad
Stop = 0      
3::
Stop := stop + 1
if stop > 3
   stop = 0
FFW()

2::
stop = 0

return


FFW()
{
Global stop
   Loop 400
   {
   SplashTextoff
   SplashTextOn,200,50,Speed, %stop%
   Send f
   if stop = 0
      break
   if Stop = 1
      Sleep 500
   if stop = 2
      sleep 150
   if stop = 3
      sleep 50
   
   }
}

I also tried the script below using getkeystate, but it is unreliable as speed increases (short sleep time).
I believe because getkeystate does not listen all the time for the key press, but only during the brief instruction execution which rarely coincide with the press.
It would equire the press to be buffered, and the buffer to be read by the getkeypress.

Unreliable script:

Code:
SetTitleMatchMode, 2
DetectHiddenText, On
#NoEnv
#Persistent
SendMode Input


#IfWinActive Notepad
Stop = 0
3:: FFW()
2:: Stop = 0
return


FFW()
{
Global Stop = 1
loop 400
   {
       Send f
   SplashTextoff
   SplashTextOn,200,50,Speed, %stop%
   if stop = 0
      break
   if Stop = 1
      Sleep 500
   if stop = 2
      sleep 150
   if stop = 3
      sleep 50
   if getkeystate("3", "p")
      Stop := stop + 1
   if stop > 3
      stop = 0
   }
}

I did succedd to get an acceptable working script with a loop on getkeystate and playing with timing, but it is still sensitive to how long you press the key.
So it would be better if we could use the trigger of the key rather than it state.

Somewhat working script:

Code:
SetTitleMatchMode, 2
DetectHiddenText, On
#NoEnv
#Persistent
SendMode Input


#IfWinActive Notepad
Stop = 0
3:: FFW()
2:: Stop = 0
return

FFW()
{
Global Stop = 1
Loop 400
   {
       Send f
   if stop = 0
      break
   if Stop = 1
   {
      Sleep 250
      loop 2
      {
      if getkeystate("3", "p")
         Stop := stop + 1
      if stop > 3
      stop = 0
      sleep 200
      SplashTextOn,200,50,Speed, %stop%
      }
   }
   if stop = 2
      loop 1
      {
      if getkeystate("3", "p")
         Stop := stop + 1
      if stop > 3
      stop = 0
      sleep 200
      SplashTextOn,200,50,Speed, %stop%
      }
   if stop = 3
      {
      if getkeystate("3", "p")
         Stop := stop + 1
      if stop > 3
         stop = 0
      sleep 50
      SplashTextOn,200,50,Speed, %stop%
      }
   }
}

Welcoming any suggestions :)
Code:


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 20th, 2009, 12:42 am 
Offline
User avatar

Joined: May 24th, 2009, 5:35 am
Posts: 2099
Location: Iowa, USA
scrambler wrote:
press 3 starts sending f at speed 1
press 3 again, go to speed 2
press 3 again, go to speed 3
press 3 again, stop

Code:
3::
If (!x || x = "off")
   x = 500
Else If (x = 500)
   x = 150
Else If (x = 150)
   x = 50
Else
   x = off
SetTimer, Label, %x%
Return

Label:
Send, f
Return


Or, even better :wink:
Code:
3:: SetTimer, Label, % x := !x || x = "off" ? 500 : (x = 500 ? 150 : (x = 150 ? 50 : "off"))

Label:
Send, f
Return

_________________
Image
Recommended: AutoHotkey_L
Basic Webpage Controls


Last edited by jethrow on August 20th, 2009, 12:53 am, edited 2 times in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 20th, 2009, 12:43 am 
Offline

Joined: July 6th, 2009, 9:58 pm
Posts: 678
oh, something like, (untested!) fixed slightly
Code:
3::
SetTimer, SendF, off


If Speed = 5 ; if speed is already at 5, disable entirely
{
   Speed = 0
}

If Speed < 5
{
     If Speed <> 0
     {
   Speed++
     }
}


If Speed = 1
{
Send, f
SetTimer, SendF, 4000 ; 4 seconds apart
}

If Speed = 2
{
Send, f
SetTimer, SendF, 2000 ;2 seconds apart
}

If Speed = 3
{
Send, f
SetTimer, SendF, 1000 ;1 second apart
}

If Speed = 4
{
Send, f
SetTimer, SendF, 500 ;half second apart
}

If Speed = 5
{
Send, f
SetTimer, SendF, 250 ;quarter second apart
}

SendF:
Send, f
Return


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 20th, 2009, 1:59 am 
Offline

Joined: August 18th, 2009, 11:08 pm
Posts: 5
Thank you both for the quick response.

Two questions:
1) if I also want to be able to interrupt the sending of f by using the 2 key, what would be the syntax? (I tried to add 2:: x = off or 2:: speed = 0) but it does not seem to affect it
2) when x reaches off state (or speed 0), does the loop stops, or does it keep running with the timmer at off.


Thank you again for the help


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 20th, 2009, 2:29 am 
Offline
User avatar

Joined: May 24th, 2009, 5:35 am
Posts: 2099
Location: Iowa, USA
Two answers:
1)
Code:
2:: SetTimer, Label, % x := "off"

2) In the example I gave, there isn't a Loop :wink:

_________________
Image
Recommended: AutoHotkey_L
Basic Webpage Controls


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 20th, 2009, 3:59 am 
Offline

Joined: July 6th, 2009, 9:58 pm
Posts: 678
scrambler wrote:
Thank you both for the quick response.

Two questions:
1) if I also want to be able to interrupt the sending of f by using the 2 key, what would be the syntax? (I tried to add 2:: x = off or 2:: speed = 0) but it does not seem to affect it
2) when x reaches off state (or speed 0), does the loop stops, or does it keep running with the timmer at off.


Thank you again for the help


Code:
2::SetTimer, SendF, off


that's it

if you use that you may or may not want another return here:

Code:
If Speed = 5
{
Send, f
SetTimer, SendF, 250 ;quarter second apart
}

Return ;this is the new return

SendF:
Send, f
Return


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 20th, 2009, 7:58 am 
Offline
User avatar

Joined: August 30th, 2005, 8:43 pm
Posts: 8666
Location: Salem, MA
RapidHotkey might also help you make it. It automatically sets up different things to happen when you press the same key a different number of times.

_________________
Image
(Common Answers) - New Tutorials Forum - Humongous FAQ


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 20th, 2009, 6:16 pm 
Offline

Joined: August 18th, 2009, 11:08 pm
Posts: 5
Thanks for all the help!

Sorry for my last post, I rushed into more questions before looking into Settimer in more details (which made the answers obvious :))

Below the final test script that I will use with CTRL+F and CTRL+B to have variable FFW and RWD in media center on video files.

Code:
SetTitleMatchMode, 2
DetectHiddenText, On
#NoEnv
#Persistent
SendMode Input

#IfWinActive Notepad
2::
SetTimer, FWS, % x := "off"
SetTimer, BWS, % y := "off"
return

3::
SetTimer, BWS, % y := "off"
If (!x || x = "off")
   x = 500
Else If (x = 500)
   x = 150
Else If (x = 150)
   x = 50
Else
   x = off
SetTimer, FWS, %x%
return

FWS:
Send, f
Return

1::
SetTimer, FWS, % x := "off"
If (!y || y = "off")
   y = 500
Else If (y = 500)
   y = 150
Else If (y = 150)
   y = 50
Else
   y = off
SetTimer, BWS, %y%
return

BWS:
Send, b
Return


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

All times are UTC [ DST ]


Who is online

Users browsing this forum: BrandonHotkey, Google [Bot], Pulover, tomoe_uehara and 52 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