AutoHotkey Community

It is currently May 27th, 2012, 3:59 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 18 posts ]  Go to page 1, 2  Next
Author Message
PostPosted: January 19th, 2006, 2:06 pm 
Offline

Joined: January 19th, 2006, 1:50 pm
Posts: 11
Hi.
I want a hotkey to maximize a window horizontally or vertically.
Is it possible? I haven't seen any options for it in the winmax function.
Also I would like to toggle between maximize and restore with the press of a singel hotkey. But how?
Please help me.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 19th, 2006, 2:40 pm 
Offline

Joined: November 8th, 2004, 12:46 am
Posts: 1271
Hi ranlun, try the following:

Code:
; Get maximised window size
sysget, SM_CXMAXIMIZED, 61
sysget, SM_CYMAXIMIZED, 62

; Get 3D border size
sysget, SM_CXEDGE, 45
sysget, SM_CYEDGE, 46
return


1::
; maxwidth
WinGetClass, class, A
WinGetPos, X, Y, W, H, A
WinMove, ahk_class %class%, , (0-(SM_CXEDGE*2)), (Y), (SM_CXMAXIMIZED)
return


2::
; maxheight
WinGetClass, class, A
WinGetPos, X, Y, W, H, A
WinMove, ahk_class %class%, , (X), (0-(SM_CYEDGE*2)), (W), (SM_CYMAXIMIZED)
return


3::
; restore original size
WinMove, ahk_class %class%, , (X), (Y), (W), (H)
return

_________________
"Anything worth doing is worth doing slowly." - Mae West
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 19th, 2006, 4:21 pm 
Offline

Joined: January 19th, 2006, 1:50 pm
Posts: 11
Thanks!!
One question. I would like that restore window function to quick in if the window is manipulated.
So if I press win+x I maximize it, if I press win+x again, it gets restored.
Is that possible?

Do you know of anyone who has tried to make a virtual dekstop application using autohotkey?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 20th, 2006, 12:18 am 
Offline

Joined: November 8th, 2004, 12:46 am
Posts: 1271
The following script will toggle the active window between maxwidth and original size:

Code:
; Get maximised window size
sysget, SM_CXMAXIMIZED, 61
sysget, SM_CYMAXIMIZED, 62

; Get 3D border size
sysget, SM_CXEDGE, 45
sysget, SM_CYEDGE, 46
return


#x::
; toggle between maximised and normal state
WinGetClass, class, A

if flag = max
{
  WinMove, ahk_class %class%, , (X), (Y), (W), (H)
  flag = min

else
{
  WinGetPos, X, Y, W, H, A
  WinMove, ahk_class %class%, , (0-(SM_CXEDGE*2)), (Y), (SM_CXMAXIMIZED) ; maxwidth
  ; WinMove, ahk_class %class%, , (X), (0-(SM_CYEDGE*2)), (W), (SM_CYMAXIMIZED) ; maxheight
  flag = max
}     
return


ranlun wrote:
Do you know of anyone who has tried to make a virtual dekstop application using autohotkey?

I'm not sure if anyone has yet, you could try searching the forum.

_________________
"Anything worth doing is worth doing slowly." - Mae West
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 20th, 2006, 8:36 am 
Offline

Joined: January 19th, 2006, 1:50 pm
Posts: 11
Thanks!!
You have been a great help :D


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 20th, 2006, 7:45 pm 
Offline

Joined: January 19th, 2006, 1:50 pm
Posts: 11
hmmm.
When I press the hotkey i toggle the windows to max, if I press it again they bacome max horizontal or max vertical. It's strange...


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 20th, 2006, 8:14 pm 
Offline

Joined: November 8th, 2004, 12:46 am
Posts: 1271
ranlun wrote:
hmmm.
When I press the hotkey i toggle the windows to max, if I press it again they bacome max horizontal or max vertical. It's strange...


The script works best if you unmaximise the target window first, otherwise it will toggle between the maxwidth and maximised states. I'm not sure if it's possible to get the unmaximised dimensions of a window whilst it is maximised.

Another "bug" is that you should restore the target window to its original size via the hotkey before switching to another window because the hotkey will apply the previous window size and position to the new active window.

_________________
"Anything worth doing is worth doing slowly." - Mae West
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 20th, 2006, 8:22 pm 
Offline

Joined: January 19th, 2006, 1:50 pm
Posts: 11
;) ok. Nice of you to try though, but now it's more work than using the mouse


Report this post
Top
 Profile  
Reply with quote  
PostPosted: January 20th, 2006, 11:12 pm 
Offline

Joined: September 25th, 2005, 4:31 pm
Posts: 610
ranlun wrote:
singel hotkey


Do you want a single hotkey to switch between each of the four states (original, max width, max height, max both)?

If not, try this:

Code:
VarSetCapacity( work_area, 16 )

DllCall( "SystemParametersInfo"
         , "uint", 0x30                                          ; SPI_GETWORKAREA
         , "uint", 0
         , "uint", &work_area
         , "uint", 0 )

work_area?w := DecodeInteger( "int4", &work_area, 8, false )-DecodeInteger( "int4", &work_area, 0, false )
work_area?h := DecodeInteger( "int4", &work_area, 12, false )-DecodeInteger( "int4", &work_area, 4, false )
return

F1:: ; maximize width
   WinMove, A,, 0,, work_area?w
return

F2:: ; maximize height
   WinMove, A,,, 0,, work_area?h
return

F3:: ; toggle maximize/restore
   if ( DllCall( "IsZoomed", "uint", WinExist( "A" ) ) )
      WinRestore, A
   else
      WinMaximize, A
return

DecodeInteger( p_type, p_address, p_offset, p_hex=true )
{
   old_FormatInteger := A_FormatInteger

   if ( p_hex )
      SetFormat, Integer, hex
   else
      SetFormat, Integer, dec
      
   sign := InStr( p_type, "u", false )^1
   
   StringRight, size, p_type, 1
   
   loop, %size%
      value += ( *( ( p_address+p_offset )+( A_Index-1 ) ) << ( 8*( A_Index-1 ) ) )
      
   if ( sign and size <= 4 and *( p_address+p_offset+( size-1 ) ) & 0x80 )
      value := -( ( ~value+1 ) & ( ( 2**( 8*size ) )-1 ) )
      
   SetFormat, Integer, %old_FormatInteger%

   return, value
}


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 21st, 2006, 1:38 pm 
Offline

Joined: January 19th, 2006, 1:50 pm
Posts: 11
Great! Now that worked!!!
I have copied the whole thing and the restore function worked!!!
How do I make the max vertical and max horizontal restore as well?
I want to be able to have a hotkey for each. One for max, one for max ver and one for max hor. And they should all toggle as well :)
Is it possible?

Thanks for the good help so far.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 22nd, 2006, 1:34 am 
Offline

Joined: September 25th, 2005, 4:31 pm
Posts: 610
Updated to save state:

Code:
VarSetCapacity( work_area, 16 )

DllCall( "SystemParametersInfo"
         , "uint", 0x30                                          ; SPI_GETWORKAREA
         , "uint", 0
         , "uint", &work_area
         , "uint", 0 )

work_area?w := DecodeInteger( "int4", &work_area, 8, false )-DecodeInteger( "int4", &work_area, 0, false )
work_area?h := DecodeInteger( "int4", &work_area, 12, false )-DecodeInteger( "int4", &work_area, 4, false )
return

F1:: ; maximize width
F2:: ; maximize height
F3:: ; toggle maximize/restore
   WinGet, hw_active, ID, A
   WinGetPos, a_x, a_y, a_w, a_h, A
   
   if windows[%hw_active%]=
   {
      windows[%hw_active%] := true
   
      windows[%hw_active%]?x := a_x
      windows[%hw_active%]?y := a_y
      windows[%hw_active%]?w := a_w
      windows[%hw_active%]?h := a_h
      
      windows[%hw_active%]?max_w := false
      windows[%hw_active%]?max_h := false
   }
   
   if A_ThisHotkey in F1,F2
   {
      if ( DllCall( "IsZoomed", "uint", hw_active ) )
         WinRestore, A
   
      if ( A_ThisHotkey = "F1" )
      {
         if ( windows[%hw_active%]?max_w )
            WinMove, A,, windows[%hw_active%]?x,, windows[%hw_active%]?w
         else
            WinMove, A,, 0,, work_area?w
            
         windows[%hw_active%]?max_w := !windows[%hw_active%]?max_w
      }
      else if ( A_ThisHotkey = "F2" )
      {
         if ( windows[%hw_active%]?max_h )
            WinMove, A,,, windows[%hw_active%]?y,, windows[%hw_active%]?h
         else
            WinMove, A,,, 0,, work_area?h
            
         windows[%hw_active%]?max_h := !windows[%hw_active%]?max_h
      }
   }
   else if ( A_ThisHotkey = "F3" )
   {
      if ( DllCall( "IsZoomed", "uint", hw_active ) )
         WinRestore, A
      else
         WinMaximize, A
   }
return

DecodeInteger( p_type, p_address, p_offset, p_hex=true )
{
   old_FormatInteger := A_FormatInteger

   if ( p_hex )
      SetFormat, Integer, hex
   else
      SetFormat, Integer, dec
      
   sign := InStr( p_type, "u", false )^1
   
   StringRight, size, p_type, 1
   
   loop, %size%
      value += ( *( ( p_address+p_offset )+( A_Index-1 ) ) << ( 8*( A_Index-1 ) ) )
      
   if ( sign and size <= 4 and *( p_address+p_offset+( size-1 ) ) & 0x80 )
      value := -( ( ~value+1 ) & ( ( 2**( 8*size ) )-1 ) )
      
   SetFormat, Integer, %old_FormatInteger%

   return, value
}


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Excellent!
PostPosted: August 9th, 2006, 3:56 am 
This.... is a great script! Exactly what I was looking for, works just like in Gnome! Good job.


Report this post
Top
  
Reply with quote  
PostPosted: August 9th, 2006, 6:01 am 
Offline

Joined: August 9th, 2006, 4:59 am
Posts: 2
It seems like this script has to be first in the file, and does not work when other keys are on the same modifier.

For instance, if you change the hotkey F2 to be ctrl z (^z), and then declare another hotkey that uses ctrl ahead of this script, the vertical maximization will simply move the window to the top of the screen instead of maximizing it.

In summary:

^b::Reload

#include maximize.ini


doesn't work. Is it an easy fix to be able to change the hotkeys in this script to make use of modifiers?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 6th, 2007, 1:18 pm 
Offline

Joined: December 14th, 2005, 3:08 pm
Posts: 219
It would be nicer if the script recorded the pid of the window (instead of class) with its X,Y, W, H dimensions into an array when the key is pressed and then when the key is pressed again it looked for a matching recorded pid and if found used those dimensions.

This would ensure it restored the same window with the old dimensions?

I tried using:

Code:
check := WinExist("A")


to get the pid, but using

Code:
WinMove, ahk_pid %class%, , (X), (Y), (W), (H)

didn't move it!

oh hum..

_________________
Stuart Halliday


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 6th, 2007, 6:19 pm 
Offline
User avatar

Joined: August 30th, 2005, 8:43 pm
Posts: 8667
Location: Salem, MA
Code:
check := WinExist("A")
WinMove, ahk_pid %check%, , (X), (Y), (W), (H)

_________________
Image
(Common Answers) - New Tutorials Forum - Humongous FAQ


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 18 posts ]  Go to page 1, 2  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: Bing [Bot], Leef_me, rbrtryn and 49 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group