Home | Blog | Software | Reviews and Features | Forum | Help | Donate | About us
topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • September 02, 2015, 06:51:15 PM
  • Proudly celebrating 10 years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: IDEA: focus get (and keep, for a while)  (Read 6763 times)

bft_chromeguy

  • Participant
  • Joined in 2008
  • *
  • Posts: 15
    • View Profile
    • Bugfree Technologies
    • Donate to Member
IDEA: focus get (and keep, for a while)
« on: October 26, 2008, 08:05:19 PM »
Hi everyppl,

I know this idea is floating around on the boards but I haven't been able to get it working properly.

Basically, I have 2 text windows open - one I want to type into all the time, and one I want to type in for short periods of time.
EG: Dreamweaver and an IM chat.

I want to be able to have the main window (dreamweaver) under focus by default, but I want to be able to click in the chatbox (or any other) and for as long as I am typing there it keeps focus. After an extended period of non-activity (eg, no more typing, say, 5~8 seconds) I want to switch back to the main window (returning to work)

The following code almost does what I want, except for the "keep focus while I am typing" part.
Code: [Select]
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
#SingleInstance, force
#Persistent
#WinActivateForce
SetTitleMatchMode, 2
Inputbox, name, Program to focus, Type the name of the program to keep in focus:, , 250, 150
if name = ; If nothing is entered for the app name exit script
{
exitapp
}
Inputbox, time, How long to wait, How long should I wait before reactivating? (milliseconds):, , 250, 150
If time =
{
time := 5000
}
SetTimer, WatchWindow, %time%
return

WatchWindow:
IfWinActive, %name%
{
return
}
Else
{
Sleep 5000
;some if-key-pressed-reset-sleep-timer code
WinActivate, %name%
}
Return
Thanks in advance
http://www.bugfreetech.com - come visit my site

TucknDar

  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 1,096
    • View Profile
    • Read more about this member.
    • Donate to Member
Re: IDEA: focus get (and keep, for a while)
« Reply #1 on: October 27, 2008, 01:52:22 AM »
Not much help from me, but just wanted to say that this sounds like an excellent idea :-[

justice

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 1,896
    • View Profile
    • Donate to Member
Re: IDEA: focus get (and keep, for a while)
« Reply #2 on: October 28, 2008, 06:42:39 AM »
I didn't really delve to deep into your script because it seemed very specific. To keep focus on a certain window:
Code: Autohotkey
  1. Win = AutoHotkey Help
  2. {
  3.         IfWinNotActive, %win%
  4.                 WinActivate, %win%
  5.         Sleep 200
  6. }
  7.  
Maybe that will help. Change Win and Sleep where appropriate.

justice

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 1,896
    • View Profile
    • Donate to Member
Re: IDEA: focus get (and keep, for a while)
« Reply #3 on: October 28, 2008, 06:44:42 AM »
Even better:

Code: Text
  1. SetTitleMatchMode, 2
  2. Win = AutoHotkey Help
  3.  
  4. WorkItBaby:
  5. WinWaitNotActive, %Win%
  6.                 WinActivate, %win%
  7. return
  8. Gosub, WorkItBaby
  9.  

bft_chromeguy

  • Participant
  • Joined in 2008
  • *
  • Posts: 15
    • View Profile
    • Bugfree Technologies
    • Donate to Member
Re: IDEA: focus get (and keep, for a while)
« Reply #4 on: October 29, 2008, 10:00:30 AM »
hi justice,
your function WorkItBaby is the same as the one in there already WatchWindow. It is already returning focus after the timeout (5 sec)
What I really want is for the timeout to become reset while I type, effectively allowing the current window to retain focus until I stop typing for a period of time.
Ideally mouse movements would reset the timeout too.
http://www.bugfreetech.com - come visit my site

skrommel

  • Fastest code in the west
  • Developer
  • Joined in 2005
  • ***
  • Posts: 886
    • View Profile
    • 1 Hour Software by skrommel
    • Donate to Member
Re: IDEA: focus get (and keep, for a while)
« Reply #5 on: November 08, 2008, 12:09:17 PM »
 :) Try ReFocus!

- Refocuses a window after 5 seconds of inactivity.
- Press F1 to change the window to refocus.

Skrommel

Code: [Select]
;ReFocus.ahk
; Refocuses a window after 5 seconds of inactivity.
; Press F1 to change the window to refocus.
;Skrommel @ 2008

idletime=5000
focus:=WinExist("Notepad")

#SingleInstance,Force
#NoEnv
SetWinDelay,0

applicationname=ReFocus

SetTimer,TIMER,1000

TrayTip,%applicationname%,- Refocuses a window after 5 seconds of inactivity.`n- Press F1 to change the window to refocus.
Return

F1::
focus:=WinExist("A")
WinGetActiveTitle,title
TrayTip,%applicationname%,%title%
Return


TIMER:
IfWinNotActive,ahk_id %focus%
If (A_TimeIdlePhysical>idletime)
  WinActivate,ahk_id %focus%
Return
Please stop by my site at  1 Hour Software by skrommel  for downloads and more info.
« Last Edit: November 08, 2008, 12:11:17 PM by skrommel »

urlwolf

  • Charter Member
  • Joined in 2006
  • ***
  • Posts: 1,794
    • View Profile
    • Donate to Member
Re: IDEA: focus get (and keep, for a while)
« Reply #6 on: November 08, 2008, 12:20:12 PM »
And skrommel is back into action!

bft_chromeguy

  • Participant
  • Joined in 2008
  • *
  • Posts: 15
    • View Profile
    • Bugfree Technologies
    • Donate to Member
Re: IDEA: focus get (and keep, for a while)
« Reply #7 on: November 10, 2008, 02:24:09 PM »
oh wow!! I never knew it would be as easy as "A_TimeIdlePhysical"
I seriously gotta delve into the docs a bit more for AHK...
skrommel, you are my hero  :Thmbsup:
http://www.bugfreetech.com - come visit my site