 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
q335r49
Joined: 26 Oct 2005 Posts: 28
|
Posted: Sat Nov 28, 2009 9:05 am Post subject: Distraction Elimination / Full Screen Script |
|
|
-- Allows you to make any application full screen by putting a border around it.
-- This is the final polished version: built-in help dialogues, cool animations, and graphical ways to customize everything. Ie, It's pretty user friendly. Give it a shot!
version 8:
| Code: |
#SingleInstance force
#NoEnv
CoordMode, ToolTip, Screen
CoordMode, Pixel, Screen
CoordMode, Mouse, screen
;version 8
Gui 2: Add, Text, section,Top:
Gui 2: Add, Text, ,Bottom:
Gui 2: Add, Text, ,Left:
Gui 2: Add, Text, ,Right:
Gui 2: Add, Edit, ys number,000
Gui 2: Add, UpDown, VTUpDown Range0-999, 0
Gui 2: Add, Edit, number,000
Gui 2: Add, UpDown, vBUpDown Range0-999, 0
Gui 2: Add, Edit, number,000
Gui 2: Add, UpDown, vLUpDown Range0-999, 0
Gui 2: Add, Edit, number,000
Gui 2: Add, UpDown, vRUpDown Range0-999, 0
Gui 2: Add, Text, xs, Trigger phrase:
Gui 2: Add, Edit, xs vTrigPhrase -WantReturn, Trigger Phrase
Gui 2: Add, Button, gEditFile xs, Edit file ...
Gui 2: Add, Button, Default gSaveToFile xs section , Save
Gui 2: Add, Button, gCancel ys, Cancel
Gui 2: +AlwaysOnTop
Menu, Tray, NoStandard
Menu, Tray, add, Define New Border..., MenuNewBorder
Menu, Tray, add, Ignore Window..., EditToolWindowList
Hotkey, Enter, Off
Hotkey, Esc, Off
Menu, Tray, add
Menu, Tray, add, Show Help, MenuHelp
HelpMode := false
Menu, Tray, add, Pause, GuiPause
Paused := false
Menu, Tray, add, Reload, MenuReload
Menu, Tray, add, Exit, MenuExit
Set4Vars(T,0,B,0,L,0,R,0)
Set4Vars(T2,0,B2,0,L2,0,R2,0)
Set4Vars(Bord_T,0,Bord_B,0,Bord_L,0,Bord_R,0)
GuiColor = 0x000000
Gui 1: Color, %GuiColor%
Gui 1: +LastFound +AlwaysOnTop +ToolWindow -Caption
Gui 1: show, % "W" . A_ScreenWidth . " H" . A_ScreenHeight . " X0 Y0", GUIWIND
WinGet, GUI_ID, ID, GUIWIND
GoSub, LoadSettingsFromFile
BorderHidden := false
PrevWinID := 00000
Loop {
If HelpMode
ShowMainHelpMessage()
PaintBorder()
If (BorderHidden) {
WaitMouseIdleOrNewActiveWindow(1200)
PaintBorder()
BorderHidden := false
}
WinWaitNotActive, ahk_id %PrevWinID%
If (PrevWinID = GUI_ID)
WaitMouseIdle(2000)
If (WinExist("A") != GUI_ID)
Sleep 500
}
Return
WaitMouseIdle(time) {
MouseGetPos, MouseX, MouseY
Loop {
Sleep, %time%
MouseGetPos, MouseX2, MouseY2
if (MouseX2 != MouseX or MouseY2 != MouseY) {
MouseX := MouseX2
MouseY := MouseY2
} else
break
}
}
WaitMouseIdleOrNewActiveWindow(time) {
global PrevWinID
MouseGetPos, MouseX, MouseY
Loop {
Sleep, %time%
MouseGetPos, MouseX2, MouseY2
NewWinID := WinExist("A")
WinGetClass, WinClass, ahk_id %NewWinID%
if InStr(IgnoreClassList, WinClass)
Continue
else if (NewWinID != PrevWinID)
Break
else if (MouseX2 != MouseX or MouseY2 != MouseY) {
MouseX := MouseX2
MouseY := MouseY2
} else
break
}
}
PaintBorder() {
global
WinGet, NewWinID, ID, A
WinGetClass, WinClass, ahk_id %NewWinID%
if InStr(IgnoreClassList, WinClass)
Return
if (NewWinID = GUI_ID) {
WinGetPos, CurLeft, CurTop, CurWinW, CurWinH, ahk_id %PrevWinID%
WinGet, Minimized, MinMax, ahk_id %PrevWinID%
if (Minimized = -1 or PrevWinID = GUI_ID) {
PrevWinID := GUI_ID
HideBorder()
} else if (NewWinW != CurWinW or NewWinH != CurWinH or NewLeft != CurLeft or NewTop != CurTop) {
WinActivate, ahk_id %PrevWinID%
WinWaitActive, ahk_id %PrevWinID%,,1
Set4Vars(LEFT, CurLeft, TOP, CurTop, BOT, A_ScreenHeight-CurTop-CurWinH, RIGHT, A_ScreenWidth-CurLeft-CurWinW)
Set4Vars(T2,TOP+Bord_T,B2,BOT+Bord_B,L2,LEFT+Bord_L,R2,RIGHT+Bord_R)
Set4Vars(NewLeft, CurLeft, NewTop, CurTop, NewWinW, CurWinW, NewWinH, CurWInH)
AnimateWindowRegion()
} else {
MouseGetPos, mX, mY
if (mX > LEFT and mX < A_ScreenWidth-RIGHT and mY > TOP and mY < A_ScreenHeight-BOT) {
WinActivate, ahk_id %PrevWinID%
WinWaitActive, ahk_id %PrevWinID%,,1
Set4Vars(T2,TOP,B2,BOT,L2,LEFT,R2,RIGHT)
BorderHidden := true
AnimateWindowRegion("none")
} else {
PrevWinID := GUI_ID
HideBorder()
}
}
} else {
WinGetActiveStats, NewWinTitle, NewWinW, NewWinH, NewLeft, NewTop
PrevWinID := NewWinID
newcolor = none
MatchFound := false
Set4Vars(T2,0,B2,0,L2,0,R2,0)
i := NumBorders
While (i >= 1) {
if (Border_%i%_5 and ((SubStr(Border_%i%_5,1,6) = "CLASS_" and InStr(WinClass, SubStr(Border_%i%_5,7))) or InStr(NewWinTitle, Border_%i%_5))) {
Set4Vars(LEFT, NewLeft, TOP, NewTop, BOT, A_ScreenHeight-NewTop-NewWinH, RIGHT, A_ScreenWidth-NewLeft-NewWinW)
Set4Vars(Bord_T, Border_%i%_1, Bord_B,Border_%i%_2, Bord_L, Border_%i%_3, Bord_R, Border_%i%_4)
Set4Vars(T2,TOP+Bord_T,B2,BOT+Bord_B,L2,LEFT+Bord_L,R2,RIGHT+Bord_R)
newcolor := Border_%i%_6
MatchFound := true
Break
}
i--
}
If (BorderAlwaysOn and not MatchFound) {
Set4Vars(LEFT, NewLeft, TOP, NewTop, BOT, A_ScreenHeight-NewTop-NewWinH, RIGHT, A_ScreenWidth-NewLeft-NewWinW)
Set4Vars(Bord_T, Border_%DefaultBorderNumber%_1, Bord_B,Border_%DefaultBorderNumber%_2, Bord_L, Border_%DefaultBorderNumber%_3, Bord_R, Border_%DefaultBorderNumber%_4)
Set4Vars(T2,TOP+Bord_T,B2,BOT+Bord_B,L2,LEFT+Bord_L,R2,RIGHT+Bord_R)
newcolor := Border_%DefaultBorderNumber%_6
}
AnimateWindowRegion(newcolor)
}
}
Set4Vars(ByRef X1, V1, ByRef X2 = "", V2 = "", ByRef X3 = "", V3 = "", ByRef X4 = "", V4 = "") {
X1 := V1
X2 := V2
X3 := V3
X4 := V4
}
AnimateWindowRegion(Color = "") {
global
T2 := (T2 < 0 or T2 > A_ScreenHeight) ? 0 : T2
B2 := (B2 < 0 or B2 > A_ScreenHeight) ? 0 : B2
L2 := (L2 < 0 or L2 > A_ScreenWidth) ? 0 : L2
R2 := (R2 < 0 or R2 > A_ScreenWidth) ? 0 : R2
Loop, 15 {
v := 16-A_Index
Set4Vars(L,L+(L2-L)/v,R,R+(R2-R)/v,T,T+(T2-T)/v,B,B+(B2-B)/v)
WinSet, Region, % "0-0 " . A_ScreenWidth . "-0 " . A_ScreenWidth . "-" . A_ScreenHeight . " 0-" . A_ScreenHeight . " 0-0 " . L . "-" . T+3 . " " . L+3 . "-" . T . " " . A_ScreenWidth-R-3 . "-" . T . " " . A_ScreenWidth-R . "-" . T+3 . " " . A_ScreenWidth-R . "-" . A_ScreenHeight-B-3 . " " . A_ScreenWidth-R-3 . "-" . A_ScreenHeight-B . " " . L+3 . "-" . A_ScreenHeight-B . " " . L . "-" . A_ScreenHeight-B-3 . " " . L . "-" . T+3, GUIWIND
Sleep, 20
}
Sleep, 200
if (Color != "none" and Color != GuiColor) {
If Color =
PixelGetColor, Color, L2, T2+4
SetFormat, integer, hex
Set4Vars(GUR,Color >> 16,GUG,mod(Color, 0x10000) >> 8,GUB,mod(Color, 0x100))
Set4Vars(PXR,GuiColor >> 16,PXG,mod(GuiColor, 0x10000) >> 8,PXB,mod(GuiColor, 0x100))
Loop, 15 {
v := 16-A_Index
Set4Vars(PXR,PXR+(GUR-PXR)//v,PXG,PXG+(GUG-PXG)//v,PXB,PXB+(GUB-PXB)//v)
GuiColor := (PXB << 16) + (PXG << 8) + PXR
Gui 1: Color, %GuiColor%
Sleep, 20
}
SetFormat, integer, d
}
}
GuiContextMenu:
Menu, Tray, show
return
GuiPause:
Paused := not Paused
Menu, Tray, ToggleCheck, Pause
If Paused
HideBorder()
While Paused
WinWaitActive, ahk_id %GUI_ID%
Return
MenuExit:
ExitApp
MenuNewBorder:
HideBorder()
WinActivate, ahk_id %GUI_ID%
MsgBox, Activate the window on which you wish to define the new border.
WinWaitNotActive, ahk_id %GUI_ID%
WinID := WinExist("A")
WinGetClass, WindowClassName, ahk_id %WinID%
WinGetPos, Left0, Top0, WinW0, WinH0, ahk_id %WinID%
GuiControl,2:,TrigPhrase,CLASS_%WindowClassName%
Gui 2: Show,,MakeCustomBorder
Saved := false
Set4Vars(LEFT, Left0, TOP, Top0, BOT, A_ScreenHeight-Top0-WinH0, RIGHT, A_ScreenWidth-Left0-WinW0)
Set4Vars(T, TOP, B, BOT, L, LEFT, R, RIGHT)
WinSet, Region, % "0-0 " . A_ScreenWidth . "-0 " . A_ScreenWidth . "-" . A_ScreenHeight . " 0-" . A_ScreenHeight . " 0-0 " . L . "-" . T+3 . " " . L+3 . "-" . T . " " . A_ScreenWidth-R-3 . "-" . T . " " . A_ScreenWidth-R . "-" . T+3 . " " . A_ScreenWidth-R . "-" . A_ScreenHeight-B-3 . " " . A_ScreenWidth-R-3 . "-" . A_ScreenHeight-B . " " . L+3 . "-" . A_ScreenHeight-B . " " . L . "-" . A_ScreenHeight-B-3 . " " . L . "-" . T+3, GUIWIND
If HelpMode
ToolTip,
(
- Adjust the borders with the arrows. Alternatively, you can
click on the edit box and mouse scroll.
- The default trigger phrase is the current window class.
If "CLASS_" is ommitted, the window title is used instead.
- Manually edit the borders by using "Edit file...".
You can do this only after defining your first border.
), 20,20
While (WinExist("MakeCustomBorder")) {
Sleep, 200
Gui 2: Submit, NoHide
Set4Vars(T,TOP+TUpDown,B,BOT+BUpDown,L,LEFT+LUpDown,R,RIGHT+RUpDown)
WinSet, Region, % "0-0 " . A_ScreenWidth . "-0 " . A_ScreenWidth . "-" . A_ScreenHeight . " 0-" . A_ScreenHeight . " 0-0 " . L . "-" . T+3 . " " . L+3 . "-" . T . " " . A_ScreenWidth-R-3 . "-" . T . " " . A_ScreenWidth-R . "-" . T+3 . " " . A_ScreenWidth-R . "-" . A_ScreenHeight-B-3 . " " . A_ScreenWidth-R-3 . "-" . A_ScreenHeight-B . " " . L+3 . "-" . A_ScreenHeight-B . " " . L . "-" . A_ScreenHeight-B-3 . " " . L . "-" . T+3, GUIWIND
}
If (Saved) {
FileAppend,`n%TUpDown%¢%BUpDown%¢%LUpDown%¢%RUpDown%¢%TrigPhrase%,CustomBorders.txt
GoSub, LoadSettingsFromFile
}
HideBorder()
If HelpMode
ShowMainHelpMessage()
Return
EditFile:
IfExist, CustomBorders.txt
{ HideBorder()
Gui 2: Hide
Run, CustomBorders.txt
Sleep, 1000
ToolTip
MsgBox,
(
Examples:
- A 10 pixel top, 15 pixel bottom, 13 pixel left, 32 pixel
right border triggered by window titles containing "Microsoft":
10¢15¢13¢32¢Microsoft
- An always purple border:
10¢15¢13¢32¢Microsoft¢FF00FF
- "ALL_WINDOWS" matches all unignored windows:
0¢0¢0¢0¢ALL_WINDOWS
- "CLASS_" matches window classes rather than titles.
10¢15¢13¢32¢CLASS_Microsoft Word
- For multiple matches, the LAST (most recently added) is used.
)
}
else
MsgBox, You can only edit Customborders.txt after saving at least one border.
Return
2GuiClose:
Cancel:
Gui, Submit
Return
SaveToFile:
Saved := true
Gui, Submit
Return
EditToolWindowList:
HideBorder()
If HelpMode
ToolTip,
(
- You may wish to ignore tool windows or dialogue
boxes that activate or deactivate the border.
- This list is stored in IgnoredWindowClasses.txt
- Currently, the ignored window classes are:
%IgnoreClassList%
),20,20
Hotkey, Enter, On
Hotkey, Esc, On
SearchingForWindow := true
While (SearchingForWindow) {
WinGetClass, ToolWinClass, A
ToolTip, Current window class is: "%ToolWinClass%"`nPress ENTER to confirm or ESCAPE to cancel,,,2
Sleep 300
}
Hotkey, Enter, Off
Hotkey, Esc, Off
ToolTip,,,,2
If HelpMode
ShowMainHelpMessage()
Return
Enter::
ToolTip,,,,2
MsgBox,4,, Append %ToolWinClass% to tool window list? (This window will not trigger the border from now on).
IfMsgBox Yes
{
FileAppend,`n%ToolWinClass%,IgnoredWindowClasses.txt
MsgBox %ToolWinClass% has been added to the list.
GoSub, LoadSettingsFromFile
}
SearchingForWindow := false
Return
Esc::
ToolTip,,,,2
SearchingForWindow := false
Return
MenuHelp:
HelpMode := not HelpMode
Menu, tray, togglecheck, Show Help
If not HelpMode
ToolTip
else
ShowMainHelpMessage()
Return
MenuReload:
Reload
Return
ShowMainHelpMessage() {
ToolTip,
(
Welcome to Universal Dark Room:
Make any application full screen!
GETTING STARTED:
- First, define a border by right-clicking on one of the four corners of the
screen and selecting "Define New Border..."
ABOUT THE BORDER:
- The border will activate on a few seconds of mouse idle.
- Deactivate by clicking on it or by switching windows.
- You can deactivate the small part of the border that covers over the window
by clicking on that part. This is helpful for temporarily showing menus.
- The border color matches pixel (0,4), which is the pixel just below the top
left triangular corner.
),20,20
}
LoadSettingsFromFile:
IfNotExist CustomBorders.txt
Gosub, MenuHelp
else
FileRead, MenuString, CustomBorders.txt
IfNotExist, IgnoredWindowClasses.txt
FileAppend, Shell_TrayWnd`n#32770`nChrome_WidgetWin_1`nNet UI Tool Window, IgnoredWindowClasses.txt
else
FileRead, IgnoreClassList, IgnoredWindowClasses.txt
NumBorders := 0
Loop, parse, MenuString, `n,`r
{ NumBorders := A_Index
Loop, Parse, A_LoopField, ¢
Border_%NumBorders%_%A_Index% := A_LoopField
if (Border_%NumBorders%_5 = "ALL_WINDOWS") {
BorderAlwaysOn := true
DefaultBorderNumber := NumBorders
}
}
Return
HideBorder() {
global
Set4Vars(T2,0,B2,0,L2,0,R2,0)
AnimateWindowRegion("none")
}
|
Last edited by q335r49 on Tue Feb 02, 2010 6:40 am; edited 19 times in total |
|
| Back to top |
|
 |
netfun81
Joined: 28 Oct 2006 Posts: 58
|
Posted: Sat Nov 28, 2009 6:43 pm Post subject: |
|
|
nice, animation is sweet Any way to make it resize for another window without opening and closing again? For example I often use alt tab to bring up another window. To get the blackness to resize I need to move the mouse to it and then it will open and resize properly. Anyway to do that automatically? Maybe detect a new window is active and resize |
|
| Back to top |
|
 |
q335r49
Joined: 26 Oct 2005 Posts: 28
|
Posted: Sun Nov 29, 2009 12:11 pm Post subject: |
|
|
| good suggestions... I made some changes to the script... it now follows the active window, but you have to click on the black part (and not merely hover over) to hide it... u can also click to hide just the window border (eg, to use the scrollbar). |
|
| Back to top |
|
 |
netfun81
Joined: 28 Oct 2006 Posts: 58
|
Posted: Sun Nov 29, 2009 7:20 pm Post subject: |
|
|
| thanks, works better for me now... one other small thing. When i have the black border in place and I maximize the window Im in, it doesnt resize, any way to get it to move with maximization? |
|
| Back to top |
|
 |
q335r49
Joined: 26 Oct 2005 Posts: 28
|
Posted: Mon Nov 30, 2009 1:30 am Post subject: |
|
|
| hmm.. how are you maximizing? Because if you hide the windowborder, and then click the maximize button, it should resize after mouse idle. |
|
| Back to top |
|
 |
netfun81
Joined: 28 Oct 2006 Posts: 58
|
Posted: Mon Nov 30, 2009 1:42 am Post subject: |
|
|
| ok i see it does resize if I leave the top border set to 45. I had all the borders set to 1px so I could see the whole window. I can live with that..thanks |
|
| Back to top |
|
 |
netfun81
Joined: 28 Oct 2006 Posts: 58
|
Posted: Wed Dec 02, 2009 9:25 pm Post subject: |
|
|
| I would like to be able to see the complete window titlebar while making the rest of the script function properly. Any easy way to disable the titlebar cover? If i set the top border to 1..then When i maximize and minimize the script won't adjust properly. |
|
| Back to top |
|
 |
q335r49
Joined: 26 Oct 2005 Posts: 28
|
Posted: Thu Dec 03, 2009 7:58 am Post subject: |
|
|
hmm... are u familiar with the scripting language at all? Because i think all you would need is a full screen black gui behind the most active window. Here's one possibility:
| Code: | Gui, Color, 000000
Gui +LastFound -Caption
Gui, show, % "W" . A_ScreenWidth . " H" . A_ScreenHeight . " X0 Y0", GUIWIND
Return
GuiClose: ;Alt-F4 to close
ExitApp |
|
|
| Back to top |
|
 |
netfun81
Joined: 28 Oct 2006 Posts: 58
|
Posted: Fri Dec 04, 2009 1:53 am Post subject: |
|
|
Thanks for the idea. Here's what I came up with:
| Code: |
Gui, Color, 000000
Gui -Caption +ToolWindow
loop
{
WinGet, 1, ID, A
sleep 500
WinGet, 2, ID, A
if 1 = %2%
gosub end
else
gui, show, w1280 h1024
WinActivate, ahk_id %2%
}
return
end:
return
|
And this one that automatically minimizes all but the active window with no gui:
| Code: |
#Persistent
loop
{
WinGet, 1, ID, A
sleep 500
WinGet, 2, ID, A
if 1 = %2%
gosub end
else
WinMinimize, ahk_id %1%
}
return
end:
return
|
There may be a more elaborate way to do this but these work. |
|
| Back to top |
|
 |
q335r49
Joined: 26 Oct 2005 Posts: 28
|
Posted: Sat Jan 23, 2010 7:10 am Post subject: |
|
|
Bumping this topic for some feedback, because I've polished everything down to a smooth, user-freindly shine. Like these sunglasses. Give it a shot, if MAXIMUM CONCENTRATION is your thing. |
|
| Back to top |
|
 |
netfun81
Joined: 28 Oct 2006 Posts: 58
|
Posted: Sat Jan 23, 2010 7:33 am Post subject: |
|
|
| wow. u are right..much better. takes a little more setup but works way better..thanks for this! |
|
| Back to top |
|
 |
q335r49
Joined: 26 Oct 2005 Posts: 28
|
Posted: Sat Jan 23, 2010 6:42 pm Post subject: |
|
|
| tx! let me know if u find any bugs / stupidities |
|
| Back to top |
|
 |
netfun81
Joined: 28 Oct 2006 Posts: 58
|
Posted: Sat Jan 23, 2010 7:38 pm Post subject: |
|
|
| one suggestion. Is there a way to use window class instead of title? I like to use this with Yahoo messenger that uses contact name for title so it's different for each window. I think a title or window class option would be cool. |
|
| Back to top |
|
 |
q335r49
Joined: 26 Oct 2005 Posts: 28
|
Posted: Sun Jan 24, 2010 7:22 pm Post subject: |
|
|
| That's def a good idea. I made it so using "CLASS_", as in "CLASS_SomeWindowClass" matches class, and the window class is automatically set as the default option when defining a new border. |
|
| Back to top |
|
 |
netfun81
Joined: 28 Oct 2006 Posts: 58
|
Posted: Mon Jan 25, 2010 7:31 pm Post subject: |
|
|
| works perfect now!...thanks for this nice script. |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|