Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate

Help! Toggle Maximize/Restore with same hotkey


  • Please log in to reply
8 replies to this topic
tic
  • Guests
  • Last active:
  • Joined: --
I've been working on a program called tic-wiiPC and it basically allows you to control your PC with a wiimote. Now the problem I'm having is that I would like to be able to Maximize and estore using the same key on the wiimote. So as an example I'd like to be able to press F12 and if the window is maximized, then restore it and vice versa.

I attempted to do this:

SysGet, VirtualScreenWidth, 78
WinGetPos, X, Y, Width, Height, A

if (%Virtualscreenwidth% = 1024) and (%Width% < 1014)
{
^$F12::WinMaximize, A  ;
}

 
if (%Virtualscreenwidth% = 1024) and (%Width% > 1014)
{
^$F12::WinRestore, A  ;
}

Basically saying that if the resolution is 1024 as width then a maximized window will have a width near that size, however autohotkey doesn't like me using the same hotkey twice!

I cam up with the idea of using a timer, making the hotkeys to maximize or restore as different keys and then press them at the same time, and have the ahk check if the active window is maximized for a certain time then restore it.....etc

Any help would be greatly appreciated and I'll be sure to credit you in my wiiPC program

nick (n-l-i)
  • Guests
  • Last active:
  • Joined: --
#NoEnv



$^F12::

SysGet, VirtualScreenWidth, 78

WinGetPos, X, Y, Width, Height, A

If (Virtualscreenwidth = 1024) {

   If (Width < 1014) {

      WinMaximize, A

   } Else {

      WinRestore, A

   }

}

Return


tic
  • Guests
  • Last active:
  • Joined: --
You legend! Very clever way of doing it as well. Hadn't thought to do it like that. I will be sure to credit you if you in my next release

engunneer
  • Moderators
  • 9162 posts
  • Last active: Sep 12 2014 10:36 PM
  • Joined: 30 Aug 2005
i don't have any computers with 1024 screen width. Am I missing some clever bit to your script?

polyethene
  • Members
  • 5519 posts
  • Last active: May 17 2015 06:39 AM
  • Joined: 26 Oct 2012
... which is why A_ScreenWidth is probably better to use.

autohotkey.com/net Site Manager

 

Contact me by email (polyethene at autohotkey.net) or message tidbit


Laszlo
  • Moderators
  • 4713 posts
  • Last active: Mar 31 2012 03:17 AM
  • Joined: 14 Feb 2005
A little simpler:
F12::

   WinGet MX, MinMax, A

   If MX

        WinRestore A

   Else WinMaximize A


tic
  • Guests
  • Last active:
  • Joined: --

i don't have any computers with 1024 screen width. Am I missing some clever bit to your script?


lol no youre not missing anything. i was going to do the same loop for all the resolutions, but laszlo has now shown me you can get the state of the window (didnt know about that with winget) thank you very much! this is very useful

dpx
  • Guests
  • Last active:
  • Joined: --
here's hoping this gets noticed, as the last post was from '07 :p

I wrote a script that brings up a little input window to search an online dictionary with the word typed in the window. I use a winkey combo, #s. what I want to do is be able to toggle the window on or off (off with winkill) with that combo, but I can't seem to get it to. I know I can't put in the same hotkey more than once, so I've been trying to find other ways around it.

ive tried toggling variables as a means of control with if checks, ive tried the minmax trick posted above, ive tried ifwinexist, ive tried using another script that had #s code in it... but it all doesn't seem to matter, since apparently while the search window is open the script won't recognize #s.

I thought it might be because the script can't intercept any keystrokes that are listed above it, but I put in a #c hotkey above it that uses winkill to kill it, and it worked. sure, this isn't quite a necessary feature, the windows does come with a cancel button, but I still want to make it toggle-able using the same hotkey. here's my code:

settitlematchmode 2

#s::
inputbox, word, Search-O-Matic, Search a word on www.dictionary.com:, , , 120, 0,875

if errorlevel
{}
else
{
ifwinexist Mozilla Firefox
{
winactivate
send {ctrldown}t{ctrlup}
send www.dictionary.com{enter}
sleep 1500
send %word%{enter}
sleep 1000
send {F6}
send {ctrldown}c{ctrlup}
gui, font, s20, verdana
gui, add, text,, URL copied to clipboard
gui show
sleep 500
gui destroy
}
else
{
msgbox, 16,, Please open Firefox before attempting to search.`nNote that Internet Explorer is not supported.
}
}
return

(I put in the explicit use of firefox because I never use ie and didn't want to code a preference thing - plus the main reason is because I didn't want to have to watch the script mess up because of variable loading times when starting the browser.)

all help is muchly appreciated!

gtolden
  • Members
  • 2 posts
  • Last active: Oct 24 2015 10:15 AM
  • Joined: 24 Oct 2015

A little simpler:

F12::

   WinGet MX, MinMax, A

   If MX

        WinRestore A

   Else WinMaximize A

I suppose you missed "return" :D

But it helps!!! Thanks