Welcome Guest.   Make a donation to an author on the site August 23, 2014, 02:17:56 PM  *

Please login or register.
Or did you miss your validation email?


Login with username and password (forgot your password?)
Why not become a lifetime supporting member of the site with a one-time donation of any amount? Your donation entitles you to a ton of additional benefits, including access to exclusive discounts and downloads, the ability to enter monthly free software drawings, and a single non-expiring license key for all of our programs.


You must sign up here before you can post and access some areas of the site. Registration is totally free and confidential.
 
Your Support Funds this Site: View the Supporter Yearbook.
   
   Forum Home   Thread Marks Chat! Downloads Search Login Register  
Pages: [1]   Go Down
  Reply  |  New Topic  |  Print  
Author Topic: IDEA: focus get (and keep, for a while)  (Read 6046 times)
bft_chromeguy
Participant
*
Posts: 15


see users location on a map View Profile WWW Give some DonationCredits to this forum member
« 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.
[copy or print]
#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
Logged

http://www.bugfreetech.com - come visit my site
TucknDar
Charter Member
***
Posts: 1,094


Advanced coder of Nowt

see users location on a map View Profile WWW Read user's biography. Give some DonationCredits to this forum member
« 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 embarassed
Logged
justice
Supporting Member
**
Posts: 1,888



Solve issues simply.

View Profile WWW Give some DonationCredits to this forum member
« 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:
Formatted for Autohotkey with the GeSHI Syntax Highlighter [copy or print]
  1. Win = AutoHotkey Help
  2. {
  3. WinActivate, %win%
  4. Sleep 200
  5. }
Maybe that will help. Change Win and Sleep where appropriate.
Logged

justice
Supporting Member
**
Posts: 1,888



Solve issues simply.

View Profile WWW Give some DonationCredits to this forum member
« Reply #3 on: October 28, 2008, 06:44:42 AM »

Even better:

Formatted for UNKNOWN with the GeSHI Syntax Highlighter [copy or print]
  1. SetTitleMatchMode, 2
  2. Win = AutoHotkey Help
  3.  
  4. WorkItBaby:
  5. WinWaitNotActive, %Win%
  6. WinActivate, %win%
  7. return
  8. Gosub, WorkItBaby
Logged

bft_chromeguy
Participant
*
Posts: 15


see users location on a map View Profile WWW Give some DonationCredits to this forum member
« 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.
Logged

http://www.bugfreetech.com - come visit my site
skrommel
Fastest code in the west
Developer
***
Posts: 882



View Profile WWW Give some DonationCredits to this forum member
« Reply #5 on: November 08, 2008, 12:09:17 PM »

 smiley Try ReFocus!

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

Skrommel

[copy or print]
;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:17 PM by skrommel » Logged

Please stop by my site at  1 Hour Software by skrommel  for downloads and more info.
urlwolf
Charter Member
***
Posts: 1,784



see users location on a map View Profile Give some DonationCredits to this forum member
« Reply #6 on: November 08, 2008, 12:20:12 PM »

And skrommel is back into action!
Logged
bft_chromeguy
Participant
*
Posts: 15


see users location on a map View Profile WWW Give some DonationCredits to this forum member
« 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
Logged

http://www.bugfreetech.com - come visit my site
Pages: [1]   Go Up
  Reply  |  New Topic  |  Print  
 
Jump to:  
   Forum Home   Thread Marks Chat! Downloads Search Login Register  

DonationCoder.com | About Us
DonationCoder.com Forum | Powered by SMF
[ Page time: 0.054s | Server load: 0.16 ]