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 

Getkeystate behaves differently under #ifWinactive

 
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
scrambler



Joined: 18 Aug 2009
Posts: 5

PostPosted: Tue Aug 18, 2009 10:18 pm    Post subject: Getkeystate behaves differently under #ifWinactive Reply with quote

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
Back to top
View user's profile Send private message
YMP



Joined: 23 Dec 2006
Posts: 418
Location: Russia

PostPosted: Wed Aug 19, 2009 2:55 am    Post subject: Reply with quote

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
}
}
Back to top
View user's profile Send private message
scrambler



Joined: 18 Aug 2009
Posts: 5

PostPosted: Wed Aug 19, 2009 5:38 pm    Post subject: Reply with quote

Thanks for the workarounds

Apreciate it !
Back to top
View user's profile Send private message
Display posts from previous:   
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