Welcome Guest.   Make a donation to an author on the site November 22, 2014, 11:50:53 PM  *

Please login or register.
Or did you miss your validation email?


Login with username and password (forgot your password?)
Why not become a lifetime supporting member of the site with a one-time donation of any amount? Your donation entitles you to a ton of additional benefits, including access to exclusive discounts and downloads, the ability to enter monthly free software drawings, and a single non-expiring license key for all of our programs.


You must sign up here before you can post and access some areas of the site. Registration is totally free and confidential.
 
Free DonationCoder.com Member Kit: Submit Request.
   
   Forum Home   Thread Marks Chat! Downloads Search Login Register  
Pages: [1] 2 Next   Go Down
  Reply  |  New Topic  |  Print  
Author Topic: DONE: Windows management script  (Read 7219 times)
tomos
Charter Member
***
Posts: 8,692



see users location on a map View Profile WWW Give some DonationCredits to this forum member
« on: August 17, 2011, 06:07:57 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 cheesy
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 embarassed
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 undecided)
« Last Edit: August 17, 2011, 07:48:25 AM by tomos; Reason: changed \"RightAlt\" to \"AltGr\" » Logged

Tom
justice
Supporting Member
**
Posts: 1,889



Solve issues simply.

View Profile WWW Give some DonationCredits to this forum member
« Reply #1 on: August 17, 2011, 07:10:36 AM »

This is a start. Untested code follows:
Formatted for Autohotkey with the GeSHI Syntax Highlighter [copy or print]
  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:10 AM by justice » Logged

tomos
Charter Member
***
Posts: 8,692



see users location on a map View Profile WWW Give some DonationCredits to this forum member
« Reply #2 on: August 17, 2011, 07:47:25 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 embarassed
Thanks Justice will try it out
Logged

Tom
justice
Supporting Member
**
Posts: 1,889



Solve issues simply.

View Profile WWW Give some DonationCredits to this forum member
« Reply #3 on: August 17, 2011, 08:10:27 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:56 AM by justice » Logged

justice
Supporting Member
**
Posts: 1,889



Solve issues simply.

View Profile WWW Give some DonationCredits to this forum member
« Reply #4 on: August 17, 2011, 08:16:50 AM »

Also you can find better shutdown / hibernate code here, than what I used (just found out):
http://www.autohotkey.com...ocs/commands/Shutdown.htm
Logged

Curt
Supporting Member
**
Posts: 6,349

see users location on a map View Profile Give some DonationCredits to this forum member
« Reply #5 on: August 17, 2011, 11:18:31 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?
Logged
skwire
Global Moderator
*****
Posts: 4,158



Another Coding Snack request? Om nom nom...

see users location on a map View Profile WWW Give some DonationCredits to this forum member
« Reply #6 on: August 17, 2011, 11:28:35 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

Formatted for Autohotkey with the GeSHI Syntax Highlighter [copy or print]
  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. }
Logged

Stoic Joker
Honorary Member
**
Posts: 5,395



View Profile WWW Give some DonationCredits to this forum member
« Reply #7 on: August 17, 2011, 11:55:28 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.
Logged
skwire
Global Moderator
*****
Posts: 4,158



Another Coding Snack request? Om nom nom...

see users location on a map View Profile WWW Give some DonationCredits to this forum member
« Reply #8 on: August 17, 2011, 01:43:47 PM »

Here's a somewhat inelegant way to minimise all except for the active window (using your AltGr-F9, I believe):

Formatted for Autohotkey with the GeSHI Syntax Highlighter [copy or print]
  1. <^>!^F9::
  2. {
  3.    CurrentWinID := WinExist( "A" )
  4.    WinRestore, ahk_id %CurrentWinID%    
  5. }

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.
Logged

tomos
Charter Member
***
Posts: 8,692



see users location on a map View Profile WWW Give some DonationCredits to this forum member
« Reply #9 on: August 17, 2011, 03:09:04 PM »

Wow, this is great Kiss

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 thumbs 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.
Logged

Tom
tomos
Charter Member
***
Posts: 8,692



see users location on a map View Profile WWW Give some DonationCredits to this forum member
« Reply #10 on: August 17, 2011, 03:21:45 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?
smiley
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...
Logged

Tom
Stoic Joker
Honorary Member
**
Posts: 5,395



View Profile WWW Give some DonationCredits to this forum member
« Reply #11 on: August 17, 2011, 03:55:13 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?
Logged
skwire
Global Moderator
*****
Posts: 4,158



Another Coding Snack request? Om nom nom...

see users location on a map View Profile WWW Give some DonationCredits to this forum member
« Reply #12 on: August 17, 2011, 04:03:02 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.
Logged

tomos
Charter Member
***
Posts: 8,692



see users location on a map View Profile WWW Give some DonationCredits to this forum member
« Reply #13 on: August 17, 2011, 04:10:46 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 smiley]. 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 Wink
Logged

Tom
tomos
Charter Member
***
Posts: 8,692



see users location on a map View Profile WWW Give some DonationCredits to this forum member
« Reply #14 on: August 17, 2011, 05:36:06 PM »

The shutdown hotkey didnt work.
[edit] user error. If it works I'll report back tomorrow!! [/edit]

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

Tom
justice
Supporting Member
**
Posts: 1,889



Solve issues simply.

View Profile WWW Give some DonationCredits to this forum member
« Reply #15 on: August 18, 2011, 03:30:59 AM »

Change the shutdown line to:
Quote
#Q::Shutdown, 8
That will definitely work because I lifted it straight from the AHK help file cheesy
Logged

tomos
Charter Member
***
Posts: 8,692



see users location on a map View Profile WWW Give some DonationCredits to this forum member
« Reply #16 on: August 18, 2011, 06:00:04 AM »

Change the shutdown line to:
Quote
#Q::Shutdown, 8
That will definitely work because I lifted it straight from the AHK help file cheesy

Yeah, the last one actually worked too - I had forgotten that I'd commented it out embarassed
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....
Logged

Tom
justice
Supporting Member
**
Posts: 1,889



Solve issues simply.

View Profile WWW Give some DonationCredits to this forum member
« Reply #17 on: August 18, 2011, 06:19:20 AM »

change
Quote
#Q::Run,shutdown -s -t 5

to
Quote
#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
}
Logged

Stoic Joker
Honorary Member
**
Posts: 5,395



View Profile WWW Give some DonationCredits to this forum member
« Reply #18 on: August 18, 2011, 06:37:49 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.
Logged
tomos
Charter Member
***
Posts: 8,692



see users location on a map View Profile WWW Give some DonationCredits to this forum member
« Reply #19 on: August 18, 2011, 06:58:30 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...
Logged

Tom
Winkie
Supporting Member
**
Posts: 82


View Profile Give some DonationCredits to this forum member
« Reply #20 on: August 18, 2011, 02:52: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?

Logged
tomos
Charter Member
***
Posts: 8,692



see users location on a map View Profile WWW Give some DonationCredits to this forum member
« Reply #21 on: August 18, 2011, 03:28:05 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 smiley
Logged

Tom
tomos
Charter Member
***
Posts: 8,692



see users location on a map View Profile WWW Give some DonationCredits to this forum member
« Reply #22 on: August 18, 2011, 03:42:01 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
Logged

Tom
Winkie
Supporting Member
**
Posts: 82


View Profile Give some DonationCredits to this forum member
« Reply #23 on: August 19, 2011, 01:04:20 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:
Formatted for Autohotkey with the GeSHI Syntax Highlighter [copy or print]
  1. #q::ComObjCreate("Shell.Application").ShutdownWindows()
Logged
tomos
Charter Member
***
Posts: 8,692



see users location on a map View Profile WWW Give some DonationCredits to this forum member
« Reply #24 on: August 19, 2011, 02:32:01 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 smiley

Thanks Winkie thumbs up
Logged

Tom
Pages: [1] 2 Next   Go Up
  Reply  |  New Topic  |  Print  
 
Jump to:  
   Forum Home   Thread Marks Chat! Downloads Search Login Register  

DonationCoder.com | About Us
DonationCoder.com Forum | Powered by SMF
[ Page time: 0.102s | Server load: 0.04 ]