topbanner_forum
  *

avatar image

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

Login with username, password and session length
  • Wednesday December 11, 2024, 3:31 pm
  • Proudly celebrating 15+ 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 14650 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 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.
#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,133
    • View Profile
    • Donate to Member
Re: IDEA: focus get (and keep, for a while)
« Reply #1 on: October 27, 2008, 01:52 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,898
    • View Profile
    • Donate to Member
Re: IDEA: focus get (and keep, for a while)
« Reply #2 on: October 28, 2008, 06:42 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 [Select]
  1. Win = AutoHotkey Help
  2. {
  3.         IfWinNotActive, %win%
  4.                 WinActivate, %win%
  5.         Sleep 200
  6. }
Maybe that will help. Change Win and Sleep where appropriate.

justice

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

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

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 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: 933
    • 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 PM »
 :) Try ReFocus!

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

Skrommel

;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
« Last Edit: November 08, 2008, 12:11 PM by skrommel »

urlwolf

  • Charter Member
  • Joined in 2006
  • ***
  • Posts: 1,837
    • View Profile
    • Donate to Member
Re: IDEA: focus get (and keep, for a while)
« Reply #6 on: November 08, 2008, 12:20 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 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