Jump to content

The Boss!


GregThompson
 Share

Recommended Posts

I thought I would release this little program I use for when my boss is lurking...

It works by reading your mouse coordinates and if the preset coordinates match up, it hides all your windows, and shows all your windows. Also if you hit CTRL + F8 it will unhide your windows, in case you can't find your unhide hotspot...

It's pretty self explanatory, enjoy!

The .zip contains both the script and the compiled .exe.

UPDATED!

Global $i, $list, $captured[500], $count = 0, $hidden = 0

HotKeySet("^{F8}", "UnHideHotKey")

MsgBox(48, "TheBoss!", "Place your mouse where you want the activation point to be in order to HIDE all your windows, and press the Enter key.")
$set1 = MouseGetPos()

MsgBox(48, "TheBoss!", "Place your mouse where you want the activation point to be in order to SHOW all your windows, and press the Enter key.")
$set2 = MouseGetPos()

MsgBox(32, "TheBoss!", "From now on all Windows will be HIDDEN when your mouse is at coordinates X = " & $set1[0] & " Y = " & $set1[1] & @CRLF & @CRLF & "Additionally, all Windows will be SHOWN again when your mouse is at coordinates X = " & $set2[0] & " Y = " & $set2[1] & "." & @CRLF & @CRLF & "If you forget, or cannot find your HIDDEN coordinates, use CTRL + F8.")

HideLoop()

Func HideLoop()
        Do
            $pos = MouseGetPos()
            $list = WinList()
            Sleep(15)
        Until $pos[0] = $set1[0] AND $pos[1] = $set1[1]
        
        For $i = 1 to $list[0][0]
        If $list[$i][0] <> "" AND SeeMe($list[$i][1]) Then
            $captured[$count] = $list[$i][0]
            $count += 1
            WinSetState($list[$i][0], "", @SW_HIDE)
            $hidden = 1
        EndIf
        Next
        ShowLoop()
EndFunc


Func ShowLoop()
        Do
            $pos = MouseGetPos()
            Sleep(15)
        Until $pos[0] = $set2[0] AND $pos[1] = $set2[1]
        
        For $i = $count to 0 Step -1
            WinSetState($captured[$i], "", @SW_SHOW)
        Next
        $hidden = 0
        $count = 0
        HideLoop()
EndFunc


Func UnHideHotKey()
    If $hidden = 1 Then
        For $i = $count to 0 Step -1
            WinSetState($captured[$i], "", @SW_SHOW)
        Next
        $hidden = 0
        $count = 0
        HideLoop()
    Else
        HideLoop()
    EndIf
EndFunc


Func SeeMe($gotcha)
    If BitAnd(WinGetState($gotcha), 2) Then 
        Return 1
    Else
        Return 0
    EndIf
EndFunc

TheBoss.zip

Edited by GregThompson
Link to comment
Share on other sites

  • Developers

I thought I would release this little program I use for when my boss is lurking...

It works by reading your mouse coordinates and if the preset coordinates match up, it minimizes all your windows.

It's pretty self explanatory, enjoy!

The .zip contains both the script and the compiled .exe.

MsgBox(48, "TheBoss!", "Place your mouse where you want the activation point to be, and press the Enter key.")

$set = MouseGetPos()

MsgBox(48, "TheBoss!", "From now on all Windows will be minimized when your mouse is at coordinates X = " & $set[0] & " Y = " & $set[1]& ".")

Loop()

Func Loop()
    Do
        $pos = MouseGetPos()
        Sleep(50)
    Until $pos[0] = $set[0] AND $pos[1] = $set[1]
    
    WinMinimizeAll()
    Loop()
EndFunc
You will get a recursion error at some point in time .... (when your boss passed by often enough)

You should not have a Func call itself unless its really needed like with a recursive directory search.

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

why would you lose your work when you hide the window? I always hide windows and nothing goes out of the ordenary when i unhide them.

anwyays, the boss could just look in your taskbar (Unless oyu got a few of the same app open)

Link to comment
Share on other sites

I like the idea, and it is clever, but you should be able to set a region, like for minimization

try like this maybe

Hotkeyset("{ESC}", "quit")

$Input1 = InputBox("TheBoss!", "Input 'X' and 'Y' coordinates for top left corner.")
$Input2 = InputBox("TheBoss!", "Input 'X' and 'Y' coordinates for bottom right corner.")

MsgBox(48, "TheBoss!", "From now on all Windows will be minimized when your mouse is at coordinates '" & $Input1 & "' to '" & $Input2 & "'.")
$Cut1= StringSplit($Input1, ",")
$Cut2= StringSplit($Input2, ",")
Loop($Cut1[1], $Cut1[2], $Cut2[1], $Cut2[2])

Func Loop($X1,$Y1,$X2,$Y2)
While 1
    For $def_x = $X1 to $X2
        For $def_y = $Y1 to $Y2
            $pos = MouseGetPos()
            If $pos[0] = $Def_x AND $pos[1] = $Def_y Then
                WinMinimizeAll()
            EndIf
        Next
    Next
WEnd
EndFunc


Func quit()
    Exit
EndFunc

In the first input, try ''0,0''

And the second one ''2,1024''

Edited by Paulie
Link to comment
Share on other sites

$Input1 = InputBox("TheBoss!", "Input 'X' and 'Y' coordinates for top left corner.")
$Input2 = InputBox("TheBoss!", "Input 'X' and 'Y' coordinates for Bottom left corner.")
oÝ÷ ØÈ ÖÞmëmz¹bëaÆ®¶­s`¢b33c´çWCÒçWD&÷gV÷CµFT&÷72b333²gV÷C²ÂgV÷C´çWBb33µb33²æBb33µb33²6ö÷&FæFW2f÷"F÷ÆVgB6÷&æW"âgV÷C²¢b33c´çWC"ÒçWD&÷gV÷CµFT&÷72b333²gV÷C²ÂgV÷C´çWBb33µb33²æBb33µb33²6ö÷&FæFW2f÷"&÷GFöÒ&vB6÷&æW"âgV÷C²

Edited by strate
INI TreeViewA bus station is where a bus stops, a train station is where a train stops. Onmy desk I have a work station...
Link to comment
Share on other sites

$Input1 = InputBox("TheBoss!", "Input 'X' and 'Y' coordinates for top left corner.")
$Input2 = InputBox("TheBoss!", "Input 'X' and 'Y' coordinates for Bottom left corner.")
oÝ÷ ØÈ ÖÞmëmz¹bëaÆ®¶­s`¢b33c´çWCÒçWD&÷gV÷CµFT&÷72b333²gV÷C²ÂgV÷C´çWBb33µb33²æBb33µb33²6ö÷&FæFW2f÷"F÷ÆVgB6÷&æW"âgV÷C²¢b33c´çWC"ÒçWD&÷gV÷CµFT&÷72b333²gV÷C²ÂgV÷C´çWBb33µb33²æBb33µb33²6ö÷&FæFW2f÷"&÷GFöÒ&vB6÷&æW"âgV÷C²
Fixed, thanks for pointing that out :P
Link to comment
Share on other sites

I didn't know that there would be problems with the loop/function. How would I go about correcting that without altering the program anymore like you guys have suggested. I think it's cool you're expanding on the idea, I just want to keep it to a single pixel activation.

So, how do I fix the recursion error potential?

@ Persen

Not sure what you're going for here, but what you're suggesting doesn't work... the code is missing the text string "" but even still... it does nothing. What are you looking to hide?

Edited by GregThompson
Link to comment
Share on other sites

The proper way to do what you are trying to do by calling a function is this:

While 1
    Do
        $pos = MouseGetPos()
        Sleep(50)
    Until $pos[0] = $set[0] AND $pos[1] = $set[1]
    
    WinMinimizeAll()
Wend

Anyone who has moderate programming experience can recommend you not to use the programming style you are now using. It is a inefficient way of creating a loop.

Link to comment
Share on other sites

I also wanted something for myself that was made to my preferences. I have also commented this alot so you might learn something from it.

; Set up a hotkey to return the hidden windows, as they are not accesable by the taskbar
HotKeySet("^{F8}", "ShowHiddenWindows")

; Set up some variables to store the winhandles of the hidden windows in, as you don't want to show everything
Global $HiddenWindows[500], $w = 0

; main loop, checks wether or not the mouse is in the left top corner.
While 1
    ;get the mouse position so it can be used for checking.
    $Pos = MouseGetPos()
    If ($Pos[0] == 0 AND $Pos[1] == 0) Then
        ; if the mouse is in the top left corner call the function WinHideAll()
        WinHideAll()
    EndIf
    ; making a loop 'take it easy' saves you a lot of CPU
    Sleep(25)
WEnd

; functions

Func WinHideAll()
    ;Get a list of all the windows.
    $WinList = WinList()
    ; make sure the operation has succeeded or you will get a error.
    If Not @error Then
        ; go through a loop of all the windows
        For $n = 1 to $WinList[0][0]
            ; if the window title isn't "Empty" go on (some windows have no titles, such as the desktop.)
            If Not $WinList[$n][0] = "" Then
                ; Get the state of the window (e.g. is it visible)
                $State = WinGetState($WinList[$n][1])
                ; uncomment the next line to get a msgbox with every window that lets you know what's going on.
                ;MsgBox(0, "Title: " & $WinList[$n][0] & " Hwnd: " & $WinList[$n][1],"State: " & $State & @CRLF & "Check 1: " & (BitAND($State,2) OR BitAND($State,32)) & @CRLF & "Check 2: " & Not ($WinList[$n][0] = "Program Manager") & @CRLF & " Sum (Will be hidden): " & ( Not ($WinList[$n][0] = "Program Manager") AND (BitAND($State,2) OR BitAND($State,32))))
                ; Check wether the window is actually visible or in the taskbar
                If (BitAND($State,2) OR BitAND($State,32)) Then
                    ; somehow there is always something called Program Manager, that's not actually a window.
                    If Not ($WinList[$n][0] = "Program Manager") Then
                        ; At this point, all the checks have passed and the window can be hidden
                        WinSetState($WinList[$n][0],"",@SW_HIDE)
                        ; store this window at point $w in a array
                        $HiddenWindows[$w] = $WinList[$n][1]
                        ;increment $w so the next window doesn't overwrite the last one in the array
                        $w += 1
                    EndIf
                EndIf
            EndIf
        Next
    EndIf
EndFunc

Func ShowHiddenWindows()
    ; this shows all the windows that are stored in the array defined for storing windows
    For $n = $w-1 to 0 Step -1 ;Windows are stored in reversed order. Therefore they are also returned that way.
        ;Show the window
        WinSetState($HiddenWindows[$n],"", @SW_SHOW)
    Next
    ;reset the counter so that windows are inserted next time at point 0
    $w = 0
EndFunc

Love

Link to comment
Share on other sites

I updated the .zip file and included the new code... Thanks for your ideas.. hope I did it "right" this time...

@ Manadar

Thanks for the post, I hadn't seen it until I already updated my code... you come across with a superior attitude as though I should be ever so thankful that you took the time to post here and "correct" me...

Turns out you and I did basically the same thing, but... yours is more in-depth... I guess I don't have moderate programming experience.

Edited by GregThompson
Link to comment
Share on other sites

@ Manadar... after comparing our 2 versions I combined them to what I wanted. I noticed with mine, because I over complicated things by using an array, I was having problems because it kept adding to the array. So, I combined the 2 into 1, which I have now upload and updated the code.

Link to comment
Share on other sites

I'll just assume this is my last update.

I added the code piece in for the HotKey using CTRL + F8 as a backup in case you can't find your unhide hotspot.

An example of the 2 spots I favor: To hide I use the bottom left, to show I use the top right...

Edited by GregThompson
Link to comment
Share on other sites

Hey good idea for nice script :P

But I would prefer INI file for specify hotspot position and maybe also for hotkeys (hide/unhide).

And also use _IsPressed for combination Ctrl + mouse position (or Alt/Shift)

And hotspot can be setup with help of @DesktopWidth, @DesktopHeight

LOL... thanks... so, basically... a completely different program, but the same idea... :nuke:

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...