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 

How do I trap a hotkey for one app while renaming another?

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



Joined: 29 Aug 2009
Posts: 4

PostPosted: Sat Aug 29, 2009 12:11 am    Post subject: How do I trap a hotkey for one app while renaming another? Reply with quote

The first section of code is for the compiled help viewer for the Visual Dataflex program. I want to be able to hit Escape to close it instead of having to hit ALT_F4. That works, but if I take out the comments, the rest of the code doesn't work.

The second section, is for the actual program, not the help file. The program shows the title of the app in the taskbar, plus the currently open workspace and filename. I only want the workspace + filename to show, so it is easy for me to tell what taskbar item is which workspace. So the Loop I have just continuously watches to see if the name of the app changes and if it does, I delete the front part of the name so that only the workspace+filename show.

This works great, but as I said before, I can't get the other part working at the same time.

I think I am in a bit of a catch22, because I want to define a hotkey, but I also need a continuous loop running. If I define the hotkey, the loop won't start until the hotkey is pressed. If I do the loop first, the hotkey will never get defined because the loop will run forever.

Is there a way to define a hotkey and then return to normal execution of the script?

Code:


/*
#IfWinActive, Visual DataFlex 12.1 Studio
Escape::WinClose

*/

RenameVDF()
{
   If WinExist("Visual DataFlex Studio")
   {
      SetTitleMatchMode, 1
      WinGetTitle, Title
      StringReplace, Title, Title, Visual Dataflex Studio 12.1 -
      WinSetTitle, %Title%      
   }
}

Loop
{
   RenameVDF()
}


[/code]
Back to top
View user's profile Send private message
horntail



Joined: 03 Aug 2009
Posts: 69
Location: UK

PostPosted: Sat Aug 29, 2009 12:29 am    Post subject: Reply with quote

Try this:

Code:
#IfWinActive, Visual DataFlex 12.1 Studio

goto, run

Escape::WinClose, Visual DataFlex 12.1 Studio

RenameVDF()
{
   If WinExist("Visual DataFlex Studio")
   {
      SetTitleMatchMode, 1
      WinGetTitle, Title
      StringReplace, Title, Title, Visual Dataflex Studio 12.1 -
      WinSetTitle, %Title%     
   }
}

run:

Loop
{
   RenameVDF()
}
Back to top
View user's profile Send private message
jakemoffatt



Joined: 29 Aug 2009
Posts: 4

PostPosted: Sat Aug 29, 2009 12:39 am    Post subject: Reply with quote

Thanks Horntail that works great!

But I don't understand why that works.

I would think that when you Goto Run

it would start the infinite loop and "Escape::..." would never get executed.

How is it that Escape still works?
Back to top
View user's profile Send private message
horntail



Joined: 03 Aug 2009
Posts: 69
Location: UK

PostPosted: Sat Aug 29, 2009 12:46 am    Post subject: Reply with quote

jakemoffatt wrote:
I would think that when you Goto Run

it would start the infinite loop and "Escape::..." would never get executed.

How is it that Escape still works?


my understanding of it is that the code is "read" by the program but not executed, meaning that it is aware of the code it just does not run 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