topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • Thursday March 28, 2024, 3:35 pm
  • Proudly celebrating 15+ years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Last post Author Topic: DONE: Windows management script  (Read 21947 times)

tomos

  • Charter Member
  • Joined in 2006
  • ***
  • Posts: 11,959
    • View Profile
    • Donate to Member
DONE: Windows management script
« on: August 17, 2011, 06:07 AM »
prompted by Skwires offer
I was hoping one of them would support Right-click on window titlebar to close.

This functionality is very easy to accomplish with a bit of AHK script.  Did you need something like that or do you currently use a different application for this functionality?
I'm now going to ask for an arm and a leg :D
I used have the majority of these running under PowerPro but haven't installed it in new Win 7 machine (& dont want to try).

Windows management (and closing OS) with suggested keys

Minimise active windowCtrl+Alt+F10 [AltGr key]
"Normalise" active windowCtrl+Alt+F11 [AltGr key]
Maximise active windowCtrl+Alt+F12 [AltGr key]
Minimise all windows except currentCtrl+Alt+F9 [AltGr key]
Close active window:
Right-click titlebar
Ctrl+Q
OS related: (see note below)
Shutdown WindowsWin+Q
Sleep WindowsWin+S (?)
Hibernate WindowsWin+H

With windows shutdown, opening the options would be just as good (like you get with Alt+F4).

I'm usually able to edit a script to change shortcuts but never did get beyond that stage :-[
I did find this list of AHK scripts
http://www.autohotkey.com/wiki/index.php?title=Script_Listing#Window_Manipulation
but couldnt find what I wanted (no, I didnt follow all links :-\)
Tom
« Last Edit: August 17, 2011, 07:48 AM by tomos, Reason: changed \"RightAlt\" to \"AltGr\" »

justice

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 1,898
    • View Profile
    • Donate to Member
Re: DONE: Windows management script
« Reply #1 on: August 17, 2011, 07:10 AM »
This is a start. Untested code follows:
Code: Autohotkey [Select]
  1. SetWorkingDir %A_ScriptDir%
  2. <^>!^F10::WinMinimize, A
  3. <^>!^F11::WinRestore, A
  4. <^>!^F12::WinMaximize, A
  5. ^Q::WinClose, A
  6. #Q::Run,shutdown -s -t 5
  7. #H::Run,rundll32 powrprof.dll`,SetSuspendState Hibernate
Can't find a working command for sleep. Also, note I have an AltGR key instead of a right alt key. Not sure if this makes a difference, but AutoHotkey help seems to think it's important to make the distinction.
« Last Edit: August 17, 2011, 07:19 AM by justice »

tomos

  • Charter Member
  • Joined in 2006
  • ***
  • Posts: 11,959
    • View Profile
    • Donate to Member
Re: DONE: Windows management script
« Reply #2 on: August 17, 2011, 07:47 AM »
Also, note I have an AltGR key instead of a right alt key. Not sure if this makes a difference, but AutoHotkey help seems to think it's important to make the distinction.

that exactly what I meant to say - it's AltGr here too :-[
Thanks Justice will try it out
Tom

justice

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 1,898
    • View Profile
    • Donate to Member
Re: DONE: Windows management script
« Reply #3 on: August 17, 2011, 08:10 AM »
If you can find out a windows 7 commandline sleep command that will help, there is a lot of discussion but I found no answers, apart from using a third party tool. Maybe someone else can bolt on right click title bar for you.

Few pointers:
To do the Minimize other windows you have to WinGet the pid of the active window,  then WinMinimizeAll, then WinRestore the current window. If you don't like that your current window minimizes then restores when you do this, you could Loop all visible windows and minimize all except the active one - however I've never been able to write code to list all current windows. Instead I had to log all windows as they became active, which means this route won't minimize windows that have not been active since the script started.
« Last Edit: August 17, 2011, 08:13 AM by justice »

justice

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 1,898
    • View Profile
    • Donate to Member
Re: DONE: Windows management script
« Reply #4 on: August 17, 2011, 08:16 AM »
Also you can find better shutdown / hibernate code here, than what I used (just found out):
http://www.autohotke...ommands/Shutdown.htm

Curt

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 7,566
    • View Profile
    • Donate to Member
Re: DONE: Windows management script
« Reply #5 on: August 17, 2011, 11:18 AM »
I understand very little of what is going on here.
On my desktop Vista "Alt+F4" will close active window/program at once. Did I get this feature from strangers?
Right-clicking a titlebar will pop up an important menu. Why would you want to disable such a feature?

skwire

  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 5,286
    • View Profile
    • Donate to Member
Re: DONE: Windows management script
« Reply #6 on: August 17, 2011, 11:28 AM »
Here's how to do your right-click titlebar request.  I've purposefully made it so that you can still right-click the titlebar icon to get the so-called SysMenu to show for a given window.  Thanks for covering the rest of the bases, Justice.   :Thmbsup:

Code: Autohotkey [Select]
  1. ~RButton::
  2. {
  3.     CoordMode, Mouse, Screen
  4.     MouseGetPos, ClickX, ClickY, hWnd
  5.     {
  6.         SendMessage, 0x84, , ( ClickX & 0xFFFF ) | ( ClickY & 0xFFFF ) << 16,, ahk_id %hWnd%
  7.         If ( ErrorLevel = 2 )
  8.         {
  9.             WinClose, ahk_id %hWnd%
  10.         }
  11.     }
  12. }
  13. Return

Stoic Joker

  • Honorary Member
  • Joined in 2008
  • **
  • Posts: 6,646
    • View Profile
    • Donate to Member
Re: DONE: Windows management script
« Reply #7 on: August 17, 2011, 11:55 AM »
I understand very little of what is going on here.
On my desktop Vista "Alt+F4" will close active window/program at once. Did I get this feature from strangers?

Nope that's normal windows behavior. Also Ctrl+F4 will close the active child in a MDI application. Come to think of it, In Windows 7, if you click (and hold) on a window, then shake it. It will minimize all other windows. Shake it again and they come back.

skwire

  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 5,286
    • View Profile
    • Donate to Member
Re: DONE: Windows management script
« Reply #8 on: August 17, 2011, 01:43 PM »
Here's a somewhat inelegant way to minimise all except for the active window (using your AltGr-F9, I believe):

Code: Autohotkey [Select]
  1. <^>!^F9::
  2. {
  3.     CurrentWinID := WinExist( "A" )
  4.     WinRestore, ahk_id %CurrentWinID%    
  5. }
  6. Return

Of course, the elegant way would be to get all IDs for all windows, loop through them and minimise all except the active window.  However, you then run the risk of minimising stuff you don't want like widgets, special hidden windows, etc.

tomos

  • Charter Member
  • Joined in 2006
  • ***
  • Posts: 11,959
    • View Profile
    • Donate to Member
Re: DONE: Windows management script
« Reply #9 on: August 17, 2011, 03:09 PM »
Wow, this is great :-*

everything is working nicely - only thing I havent tested yet is shutdown. **

Here's a somewhat inelegant way to minimise all except for the active window [...]
this works well -
and what with win7 graphics it looks fine too :up:

Re shutdown (remember, not tested yet), is there a way of raising the Alt+F4 windows shutdown dialogue?
That way I would get to choose exactly what I want, but more importantly I would have to confirm, so I would be covered in case of mistaken use of shortcut.
Tom

tomos

  • Charter Member
  • Joined in 2006
  • ***
  • Posts: 11,959
    • View Profile
    • Donate to Member
Re: DONE: Windows management script
« Reply #10 on: August 17, 2011, 03:21 PM »
I understand very little of what is going on here.
On my desktop Vista "Alt+F4" will close active window/program at once. Did I get this feature from strangers?
:)
I've always considered Alt+F4 a fairly tortuous shortcut to use. You dont have to be quite so acrobatic to use it with your right hand, but then it's on the wrong side of the keyboard.
Ctrl+Q is used in many graphics programmes (I think maybe it was 'ported' from earlier mac versions - where I think it is the default shortcut).

Right-clicking a titlebar will pop up an important menu. Why would you want to disable such a feature?

I've actually never in my life used that menu except to close a window, so at some stage I picked up the right-click to close idea.

It's possibly because I have to use a mouse all day (with work) that I really try to avoid the extra journey into the corner, or even using the mouse at all - but I suspect it's probably got more to do with my impatience in general...
Tom

Stoic Joker

  • Honorary Member
  • Joined in 2008
  • **
  • Posts: 6,646
    • View Profile
    • Donate to Member
Re: DONE: Windows management script
« Reply #11 on: August 17, 2011, 03:55 PM »
I've never had a problem with Alt+F4, but then again I am left handed...

Double clicking the left corner of the titlebar will also close a window by default. But I'm curious as to why right clicking the titlebar would be easier than using the red X in the right corner. Do you have a lot of large multi monitor windows?

skwire

  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 5,286
    • View Profile
    • Donate to Member
Re: DONE: Windows management script
« Reply #12 on: August 17, 2011, 04:03 PM »
Regarding Alt-F4, I've always used two hands.  Right-hand thumb on the Alt key and left-hand index finger to press the F4 key.

But I'm curious as to why right clicking the titlebar would be easier than using the red X in the right corner.

Fitt's Law.  There's a lot more titlebar caption space to click in comparison to the close button.

tomos

  • Charter Member
  • Joined in 2006
  • ***
  • Posts: 11,959
    • View Profile
    • Donate to Member
Re: DONE: Windows management script
« Reply #13 on: August 17, 2011, 04:10 PM »
Double clicking the left corner of the titlebar will also close a window by default. But I'm curious as to why right clicking the titlebar would be easier than using the red X in the right corner. Do you have a lot of large multi monitor windows?

I think I started using the right-click with an AHK script years ago (Nifty Windows? it was buggy so I transferred it to PowerPro). And it does save time and effort, even with single monitor & full screen app [& Fitt's Law of course :)]. I avoid doubleclicks like the plague - when I'm drawing, I can get through a few thousand mouse-clicks a day. I would prefer almost anything to a double click ;)
Tom

tomos

  • Charter Member
  • Joined in 2006
  • ***
  • Posts: 11,959
    • View Profile
    • Donate to Member
Re: DONE: Windows management script
« Reply #14 on: August 17, 2011, 05:36 PM »
The shutdown hotkey didnt work.
[edit] user error. If it works I'll report back tomorrow!! [/edit]

older version...
Not a biggee, but if this were possible:

Re shutdown (remember, not tested yet), is there a way of raising the Alt+F4 windows shutdown dialogue?
That way I would get to choose exactly what I want, but more importantly I would have to confirm, so I would be covered in case of mistaken use of shortcut.

Edit/ and I had to disable Hibernate earlier, not working properly, ah well...

Edit #2/ weird side-effect - if I right-click on the script, the shutdown dialogue shows as long as I keep right button pressed :)

Tom
« Last Edit: August 17, 2011, 05:45 PM by tomos »

justice

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 1,898
    • View Profile
    • Donate to Member
Re: DONE: Windows management script
« Reply #15 on: August 18, 2011, 03:30 AM »
Change the shutdown line to:
#Q::Shutdown, 8
That will definitely work because I lifted it straight from the AHK help file :D

tomos

  • Charter Member
  • Joined in 2006
  • ***
  • Posts: 11,959
    • View Profile
    • Donate to Member
Re: DONE: Windows management script
« Reply #16 on: August 18, 2011, 06:00 AM »
Change the shutdown line to:
#Q::Shutdown, 8
That will definitely work because I lifted it straight from the AHK help file :D

Yeah, the last one actually worked too - I had forgotten that I'd commented it out :-[
But it works scarily good :tellme: - everything gets killed, no questions asked (so far).
Anyone know if it's possible to bring up the shutdown dialogue? That would feel safer....
Tom

justice

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 1,898
    • View Profile
    • Donate to Member
Re: DONE: Windows management script
« Reply #17 on: August 18, 2011, 06:19 AM »
change
#Q::Run,shutdown -s -t 5

to
#Q::
{
Run,shutdown -s -t 30
Msgbox, 1,,Computer is shutting down in 30 seconds. Press cancel to abort.,30
IfMsgBox, Cancel
  Run,shutdown -a
}

Stoic Joker

  • Honorary Member
  • Joined in 2008
  • **
  • Posts: 6,646
    • View Profile
    • Donate to Member
Re: DONE: Windows management script
« Reply #18 on: August 18, 2011, 06:37 AM »
Why not just have the key combination bring up a system modal dialog with shutdown, reboot, sleep, and cancel options? Sure it's an extra click, but it'll cleanly bypass the oh shit factor.

tomos

  • Charter Member
  • Joined in 2006
  • ***
  • Posts: 11,959
    • View Profile
    • Donate to Member
Re: DONE: Windows management script
« Reply #19 on: August 18, 2011, 06:58 AM »
Why not just have the key combination bring up a system modal dialog with shutdown, reboot, sleep, and cancel options? Sure it's an extra click, but it'll cleanly bypass the oh shit factor.
if it's possible,
that would be best option I think, also with having all the choices at hand.


@justice - the last change works, but not very well - the cancel option is hidden behind the message that it will close in 30 seconds.
One of the previous versions also said it would close in 30 secs, but closed after literally a couple of seconds, so I'm a bit wary of it...
Tom

Winkie

  • Supporting Member
  • Joined in 2008
  • **
  • Posts: 93
    • View Profile
    • Donate to Member
Re: DONE: Windows management script
« Reply #20 on: August 18, 2011, 02:52 PM »
It should be possible to show the standard Windows shutdown dailog. At least, ShutdownWindows works on my WinXP system (Can't test it on Win7).
@tomos: what AutoHotkey version do you use?


tomos

  • Charter Member
  • Joined in 2006
  • ***
  • Posts: 11,959
    • View Profile
    • Donate to Member
Re: DONE: Windows management script
« Reply #21 on: August 18, 2011, 03:28 PM »
It should be possible to show the standard Windows shutdown dailog. At least, ShutdownWindows works on my WinXP system (Can't test it on Win7).
@tomos: what AutoHotkey version do you use?

1.0.47.06 - seems to qualify but I may as well bring it up-to-date:
I see there's a 64bit version - would you recommend that?

I'll try one of those options from that link later - thanks!!

feels like between windows updates and testing here I've rebooted about 10 times in the last 24 hours :)
Tom

tomos

  • Charter Member
  • Joined in 2006
  • ***
  • Posts: 11,959
    • View Profile
    • Donate to Member
Re: DONE: Windows management script
« Reply #22 on: August 18, 2011, 03:42 PM »
It should be possible to show the standard Windows shutdown dailog. At least, ShutdownWindows works on my WinXP system (Can't test it on Win7).

tried the first example, it works :Thmbsup:
Tom

Winkie

  • Supporting Member
  • Joined in 2008
  • **
  • Posts: 93
    • View Profile
    • Donate to Member
Re: DONE: Windows management script
« Reply #23 on: August 19, 2011, 01:04 PM »
I see there's a 64bit version - would you recommend that?
Not sure about that. I have no experience with 64-bit.

tried the first example, it works

But if you want to update to AHK_L the hotkey can become this:
Code: Autohotkey [Select]
  1. #q::ComObjCreate("Shell.Application").ShutdownWindows()

tomos

  • Charter Member
  • Joined in 2006
  • ***
  • Posts: 11,959
    • View Profile
    • Donate to Member
Re: DONE: Windows management script
« Reply #24 on: August 19, 2011, 02:32 PM »
I see there's a 64bit version - would you recommend that?
Not sure about that. I have no experience with 64-bit.
[...]
But if you want to update to AHK_L the hotkey can become this:

"AHK_L" has a 64bit option when installing,
and, yes, your shortened version works perfectly with it :)

Thanks Winkie :up:
Tom