ATTENTION: You are viewing a page formatted for mobile devices; to view the full web page, click HERE.

DonationCoder.com Software > Coding Snacks

IDEA: focus get (and keep, for a while)

(1/2) > >>

bft_chromeguy:
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

TucknDar:
Not much help from me, but just wanted to say that this sounds like an excellent idea :-[

justice:
I didn't really delve to deep into your script because it seemed very specific. To keep focus on a certain window:

--- Code: Autohotkey ---SetTitleMatchMode, 2Win = AutoHotkey HelpLoop,{        IfWinNotActive, %win%                WinActivate, %win%        Sleep 200}Maybe that will help. Change Win and Sleep where appropriate.

justice:
Even better:


--- Code: Text ---SetTitleMatchMode, 2Win = AutoHotkey Help WorkItBaby:WinWaitNotActive, %Win%                WinActivate, %win%returnGosub, WorkItBaby

bft_chromeguy:
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.

Navigation

[0] Message Index

[#] Next page

Go to full version