AutoHotkey Community

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

All times are UTC [ DST ]




Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: August 18th, 2009, 11:18 pm 
Offline

Joined: August 18th, 2009, 11:08 pm
Posts: 5
below is a test script (to use with notepad) that sends up to 100 f when I hit 3 (or up to 100 b when I hit 1) and stops when I hit 2 but whitout displaying the 2. This ultimately is used to do a fastForward and rewind using skip commands.

test scripts:
Code:
SetTitleMatchMode, 2
DetectHiddenText, On
#NoEnv
#Persistent
SendMode Input 
1:: RWD()      
3:: FFW()
2:: Send {}
return

FFW()
{
loop 100
   {
       Send f
       Sleep 30 
   if getkeystate(2) = true
   break
   }
}
RWD()
{
loop 100
   {
       Send b
       Sleep 30 
   if getkeystate(2) = true
   break
   }
}

My problem is that if I add a #ifWinactive command to restrict the behavior to a certain application (like #IfWinActive Notepad), then pressing 2 does not work any more to interrupt the loop.
Script that does not work below:

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

#IfWinActive Notepad
1:: RWD()      
3:: FFW()
2:: Send {}
return

FFW()
{
loop 100
   {
       Send f
       Sleep 30
   if getkeystate(2) = true
   break
   }
}
RWD()
{
loop 100
   {
       Send b
       Sleep 30
   if getkeystate(2) = true
   break
   }
}

When there is a #IfWinActive statement, it only works if I remove the "2:: Send {}" instruction, but then of course the 2 shows up when interrupting the loop.

Can someone shade some light on why this is and let me know if there is a workaround.
I want to be able to break the loop by hitting 2, but not actually sending the 2 to the active window.

Thanks


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

Joined: December 23rd, 2006, 6:02 pm
Posts: 424
Location: Russia
Strange behaviour, indeed, at first glance. But I suspect we are just missing something and it has an explanation.

The simplest workaround, in my opinion:
Code:
SetTitleMatchMode, 2
DetectHiddenText, On
#NoEnv
#Persistent
SendMode Input

#IfWinActive Notepad
1:: RWD()
3:: FFW()
2:: Stop = 1

FFW()
{
Global Stop = 0
loop 100
{
Send f
Sleep 30
if Stop
break
}
}
RWD()
{
Global Stop = 0
loop 100
{
Send b
Sleep 30
if Stop
break
}
}

Or if you insist on using GetKeyState(), check the physical state of the key, it also works for me:
Code:
SetTitleMatchMode, 2
DetectHiddenText, On
#NoEnv
#Persistent
SendMode Input

#IfWinActive Notepad
1:: RWD()
3:: FFW()
2:: Return

FFW()
{
loop 100
{
Send f
Sleep 30
if getkeystate("2", "p")
break
}
}
RWD()
{
loop 100
{
Send b
Sleep 30
if getkeystate("2", "p")
break
}
}


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

Joined: August 18th, 2009, 11:08 pm
Posts: 5
Thanks for the workarounds

Apreciate it !


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

All times are UTC [ DST ]


Who is online

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