Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

handy & useful - move windows aside to access your deskt


  • Please log in to reply
8 replies to this topic
Terrapin
  • Members
  • 107 posts
  • Last active: Feb 06 2007 03:38 PM
  • Joined: 15 Aug 2005
This is my first post, and first script "release." I've been playing with AHK for about a month, took a little while to get the hang of it, now things are coming along pretty quickly. I used to code for DOS, gave up when win95 debuted.

This is called "Reveal Desktop" or simply "Reveal." It is a blatantly stolen idea from one of my favorite shareware utilities. I have posted a zip file if you care to download it contains source, executable, and a brief bit of a text file. Let me see if I can figure how to paste the source here. - Ok, it looks awfully long here. :oops: The zip file I mentioned is at
http://deepelem.us/ahk/reveal.zip

I'd love to hear any comments, nice ones, helpful ones, etc. You may see something I could have done a better way. It is heavily commented as you can see. Posted Image

; 	    Title: 		Reveal Desktop
;           Coder:		Terrapin aka Bob Allred
;           Email: 		rka1961@etinternet
;            Date: 		22 Sept 2005
;  AutoHotKey Ver:     	1.0.38.03
;  	   Script Ver:	0.9 (first release)
;Purpose/Function:	Mostly for fun & learning/practice.  Temporarily uncovers 
;						a window-cluttered desktop in a cool and useful manner.  
;						Idea from the VDM goScreen at http://goScreen.info	
;			Usage:		Hold down the Right Mouse Button while clicking the Left 
;						Button to slide open, visible windows off either side of the 
;						screen until the next Left Click, which will bring them back.  
;						A sliding/transition effect.  Allows you to click something on 
;						the desktop when the screen is cluttered.

SetWinDelay, -1   		; want to move pretty fast

+!g::					; fire shift-alt-g - an ad for a great shareware utility 
msgbox, 4164, Blatant Ad... , Take a look at Andrei's site -`nA GREAT Virtual Desktop Manager!
IfMsgBox, Yes
{
	Run, http://goscreen.info
}
Return

^!+q::			; hotkey to close the script quick & easy
exitapp

			; Finally, the Fun
+#r::					; If you'd rather use a hotkey, comment out the moust triggers 
RButton & LButton::   	; easy mouse trigger - click left button while holding down right
Slide:					;   .... to show the desktop temporarily in a cool effect
{
Slid = true
GoSub, GetVDimensions	; get vitrual screen in case multi-monitor, but not tested
GoSub, GetWinDimensions	; get the upper left corner, width & height of each visible window
GoSub, WinInfo			; ... and of windows & do some figuring

ScrnLeft := X0 + 40		; don't move windows *quite* all the way off-screen
ScrnRight := X0 + VWidth - 40	
			
Loop, 40				; kind of an arbitrary number of maximum slides (steps) educated guess								
{
	i = %WinArray%		; number of windows being slid
	Loop, %i%			; cycle through list of visible windows
	{
		If WinTitle%A_Index% <>			; if the window has no title, most likely leave it be
		{  
			If (x2%A_Index% > ScrnLeft)	; we won't slid a window any more once 
			{							; .... once it is at Left edge of screen
				If (x1%A_Index% < ScrnRight)	; ditto - left side if moving left
				{
					
	hwnd := WinArray%A_Index%		; easy to use this simple var each time around
	If Side%A_Index% = L			; for each window, slide it off the side of 
		step = -30					; .... the screen it is on
	If Side%A_Index% = R			; ... LEFT or RIGHT
		step = +30					; by 30 pixels per step
		
	NumMoves%A_Index%++				; count how many times we moved the window so
									; ... we can return it the same way later
	x1%A_Index% += %step%			; these two lines set up to slide windows a step at	
	x2%A_Index% += %step%			; .. a time of 30 pixels per step
	x1 := x1%A_Index%				; move array element to a simpler var
	y1 := y1%A_Index%				; just using left and right sides, so y doesn't change
	WinMove, ahk_id %hwnd% , , x1, y1	; and slide the window, finally
	moved%A_Index% = true			; save to remember to move this one back - just a
				}					; 	... corresponding array of flags
			}
		}	
	}
}
Return
}		

~LButton::					; if you comment out the trigger click above, do this one too
SlideBack:					; this slides the windows back to their original positions
{
i = %WinArray%

Loop, 40
{
	Loop, %i%
	{
		If moved%A_Index%					; check each windows flag so only sliding back
		{									;   ... the ones we moved in the first place
			hwnd := WinArray%A_Index%
			If Side%A_Index% = L			; 
				step = +30					; reverse direction
			If Side%A_Index% = R			; 
				step = -30					; by 30 pixels per step		
			If NumMoves%A_Index% > 0		; remember, we counted the moves for each window
			{								; ... so we know how many times to slide it back
				NumMoves%A_Index%--			; decrement the number of moves each time we slide
				x1%A_Index% += %step%		; set up to move window back one "step" (30 pixels)
				x2%A_Index% += %step%				
				x1 := x1%A_Index%
				y1 := y1%A_Index%
				WinMove, ahk_id %hwnd%, , x1, y1	; move it
			}
		}
	}
}
Return
}			
			

*RButton Up::				; pass on through that Right "shift" button

{
If Not %Slid%				; only pass along the right button click if it wasn't used by this app
{
	Slid := Not Slid	; turn off flag
	Send, {RButton}		; guess :)
}
return
}			
			
			
Decide(cx)   					; pass this function the horizontal window center...
{
	If  (cx < ScrnXCenter())  	; it will compare it to the horiz screen center
		Side = L				;   ... to decide which side of the screen the 
	Else						; ... window is on, Left 
		Side = R				; .... or Right

Return, Side					; when we slide, windows on the left side of the screen
}								;    .... will go left, and vice versa

GetWinDimensions:
{
DetectHiddenWindows, Off    	; only act on visible windows
WinGet, WinArray, List			; get # of visible windows and each window handle into array
i = %WinArray%  		    	; use this variable for loops
	
Loop, %i%						; execute loop once per window
{
	hwnd := WinArray%A_Index%	; var for ahk_id for each window as we loop
; below - get location and size of each window as we loop -- and window titles
	WinGetPos, WinArray%A_Index%_X, WinArray%A_Index%_Y, WinArray%A_Index%_W, WinArray%A_Index%_H, ahk_id %hwnd%
	WinGetTitle, WinTitle%A_Index%, ahk_id %hwnd%
}
DetectHiddenWindows, On			; I normally keep it on, what the heck
Return
}

WinInfo:
{
i = %WinArray%						; number of found visible windows

Loop, %i%							; get various info for each window
{

	Title := WinTitle%A_Index% 		; obvious... I hope
	x1 := WinArray%A_Index%_X    	; Left....
	y1 := WinArray%A_Index%_Y		;  .... Top corner of the current window
	width := WinArray%A_Index%_W	; width and ...
	height := WinArray%A_Index%_H	; .... height of the current window
	x2 := x1 + width				; calculate right side of each window...
	y2 := height + y1				; ....as well as the bottom side
	cx := width/2+x1				; horizontal center of window - using virtual screen....
	cy := height/2+y1				; .. in case dual monitors - this gets vertical center
	x1%A_Index% = %x1%				; store left side locations in an array matching the hwnd array
	x2%A_Index% = %x2%				; ditto for right sides
	cx%A_Index% = %cx%				; ditto for horizontal centers
	side%A_Index% := Decide(cx)		; this calls a function which determines which horizontal
									;   .. side of the screen each window is located
}
Return
}

GetVDimensions:			; using virtual screen dimensions
{
SysGet,X0,76
SysGet,Y0,77
SysGet,VWidth,78
SysGet,VHeight,79
Return
}

; function names should make these clear
WinXCenter(WinID)
{
WinGetPos, , , width, , ahk_id %WinID%
Return, width/2
}

WinYCenter(WinID)
{
WinGetPos, , , , height, ahk_id %WinID%
Return, height/2
}

ScrnXCenter()
{
SysGet,x,76
SysGet,VWidth,78
Return, (VWidth/2)+x
}

ScrnYCenter()
{
SysGet,y,77
SysGet,VHeight,79
Return, (VHeight/2)+y
}

When it comes to Binary, there are 10 types of people. Those who get it and those who don't. :)

Chris
  • Administrators
  • 10727 posts
  • Last active:
  • Joined: 02 Mar 2004
It looks nifty. Thanks for sharing it.

Nemroth
  • Members
  • 278 posts
  • Last active: Dec 31 2011 10:53 PM
  • Joined: 07 Sep 2004
Very funny, and usefull. Improvement suggested : hide completely the windows, provide a hotkey to restore them in their original place but being able tu use desktop (so without restoring windows when you click on it).

gast
  • Guests
  • Last active:
  • Joined: --

heavily commented as you can see

thanks

Dewi Morgan
  • Members
  • 191 posts
  • Last active: Jun 07 2015 04:02 AM
  • Joined: 03 Oct 2005
I may be slow, but what's the advantage of this over the (windows key + D) builtin windows key combo?
Yet another hotkeyer.

songsoverruins
  • Members
  • 46 posts
  • Last active: Sep 25 2015 08:43 PM
  • Joined: 01 Oct 2005
I was just thinking the same thing as Dewi Morgan. It must have been a good exercise but windows already has an inbuilt key for this sort of thing... either way, nice to have people join the bandwagon.

Don't let this put you off in developing code and putting it out for everyone to see :)
For the music lover who can sit and enjoy the sound of someone else's evolving nightmare.

Terrapin
  • Members
  • 107 posts
  • Last active: Feb 06 2007 03:38 PM
  • Joined: 15 Aug 2005
Hi. I did mainly do this as an 'exercise' in learning (it may say that in the preface). I have a 'desktop manager' utility which includes this very same function, so it is not like I needed to recreate it. :) But I wanted to see if I could.

I just tried win-d and it seems to minimize all windows? If that is what it does, this does have the advantage of just moving them out of the way to access a desktop icon, then automatically moving them back. I have it programmed to a mouse-click combination, and use it quite a bit.

The author of the desktop manager (goScreen) pointed out to me that he got the idea from - I believe it is Apple Expose.

best,
When it comes to Binary, there are 10 types of people. Those who get it and those who don't. :)

SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005
Nice utility Terrapin.
I am using it ..

Thanks for sharing :-)
kWo4Lk1.png

psionics
  • Guests
  • Last active:
  • Joined: --
very nice application. thanks very much