AutoHotkey Community

It is currently May 27th, 2012, 11:33 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 15 posts ] 
Author Message
PostPosted: August 22nd, 2005, 12:15 pm 
Offline

Joined: August 22nd, 2005, 12:10 pm
Posts: 2
I disovered ahk a couple of hours back, and wrote this to do what
I always wanted to do ... Dynamically give hotkeys to open windows,
to switch quickly from one to other.

With this you can:
1. Use Win+Ctrl+0..9 to attach hotkey to current active window.
2. Use Win+0..9 to switch to corrospoding window.


--enjoy and improvise.

Code:
;;;;; Dynamic hot key to windows ....
;;;;; To see current assignment, see values of variable var0-9
;;;Win-Control-n --> Assign window to this hot key
;;;Win-n         --> Switch to window with this hot key
;;;Win-Alt-n     --> Iconize others and do this


DynHotkey( ByRef var , what)
{
  if ( what == 0 ) ;; Save
  {
      WinGetActiveStats, var, w,h,x,y
      return
  }
  if ( what == 1 ) ;; Switch
  {
       WinActivate, %var%
       return
  }
  if ( what == 2 ) ;; IconizeAll, Switch
  {
       WinMinimizeAll
       WinActivate, %var%
       WinRestore, %var%
       return
  }

}

#^0::DynHotKey(var0,0)
#0::DynHotKey(var0,1)
#!0::DynHotKey(var0,2)


#^1::DynHotKey(var1,0)
#1::DynHotKey(var1,1)
#!1::DynHotKey(var1,2)

#^2::DynHotKey(var2,0)
#2::DynHotKey(var2,1)
#!2::DynHotKey(var2,2)

#^3::DynHotKey(var3,0)
#3::DynHotKey(var3,1)
#!3::DynHotKey(var3,2)

#^4::DynHotKey(var4,0)
#4::DynHotKey(var4,1)
#!4::DynHotKey(var4,2)

#^5::DynHotKey(var5,0)
#5::DynHotKey(var5,1)
#!5::DynHotKey(var5,2)

#^6::DynHotKey(var6,0)
#6::DynHotKey(var6,1)
#!6::DynHotKey(var6,2)

#^7::DynHotKey(var7,0)
#7::DynHotKey(var7,1)
#!7::DynHotKey(var7,2)

#^8::DynHotKey(var8,0)
#8::DynHotKey(var8,1)
#!8::DynHotKey(var8,2)

#^9::DynHotKey(var9,0)
#9::DynHotKey(var9,1)
#!9::DynHotKey(var9,2)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 22nd, 2005, 5:32 pm 
Offline

Joined: February 14th, 2005, 4:05 pm
Posts: 4710
Location: Boulder, CO
Nice idea! And it works.
If you like experimenting with a working script, you can shorten it a little by using the hotkey command and a loop. Also, it is safer to use the unique ID of a window, instead of its title (in case there are conflicting titles), and you don't have to worry about the title matching modes.
Code:
Loop 10
{
   i := A_Index - 1
   HotKey #^%i%,DynHotkey
   HotKey #%i%, DynHotkey
   HotKey #!%i%,DynHotkey
}
Exit

DynHotkey:
   StringRight i, A_ThisHotKey, 1
   StringMid what,A_ThisHotKey, 2, 1
   var := var%i%
   IfEqual what, ^, WinGet var%i%, ID, A  ; Save ID
   Else IfEqual what,!, WinMinimizeAll    ; MinimizeAll
   WinRestore  ahk_id %var%
   WinActivate ahk_id %var%               ; Switch
Return
Edit 2005.08.23: trimmed off another couple of lines


Last edited by Laszlo on August 23rd, 2005, 4:17 pm, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 23rd, 2005, 5:07 am 
Offline

Joined: August 22nd, 2005, 12:10 pm
Posts: 2
Hello,
Thanx for shortening it.

Can you pls explain why the 'A' in 'WinGet var, ID, A' should get the
active window ? I noticed that documenation refers to WinExist("A")
to get active window, but what is so special about "A" ?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 23rd, 2005, 11:38 am 
Offline

Joined: January 31st, 2005, 9:50 am
Posts: 3910
Location: Bremen, Germany
Please have a look at the manual for "last found window". There you'll find beside other usefull information this:
Quote:
Almost all of the windowing commands can be told to operate upon the active window by specifying the letter A as the WinTitle parameter and omitting WinText, ExcludeTitle, and ExcludeText.

_________________
Ciao
toralf
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 25th, 2005, 2:31 am 
Offline

Joined: July 29th, 2005, 5:32 pm
Posts: 179
You might want to check out this script i posted a while ago:

http://www.autohotkey.com/forum/viewtopic.php?t=4721

It makes Win 1-9 & 0 (on top of keyboard & on side numeric pad) to be hotkeys that perform a variety of functions. I also have built in shortcuts for capturing info when the gui window is minimized to system tray (like your active window script..)

Left Ctrl+Left Alt+<1-10> = Sets that number hotkey to either activate, minimize, or maximize the currently active window (you can specify default action on the settings tab...)

Right Alt+<1-10> = Sets hotkey to either left click, right click, or simply move to where you currently have mouse.

win+Left shift+<1-10> = If you have text highlighted-- it will copy it.. & set specified hotkey to send those keystrokes (think of it as an extension to clipboard..)

win+numeric pad minus key = Takes a screenshot of either the whole screen- or the currently active window.. & saves as a JPG in folder you are running script from.

Alt+Left click/drag = Lets you draw a box around portion of screen to take screen shot of. Once released- JPG will be saved in folder you are running script from.

I also have other functions on there like a built in editor to help you arrange more complex multiple step macros, a simple hotstring editor, an autocomplete feature (you specify which windows to work for..), and an option to export your hotkey macros that you've created to an AHK file (or to an EXE file if you put a copy of the Ahk2Exe.exe, AutoHotkeySC.bin, & upx.exe in the same folder your running script from..). I'm still working on it-- so I'm currently working on a new & improved version. Let me know if there are any new features you want to see added. :D

_________________
.o0[ corey ]0o.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 25th, 2005, 3:26 am 
Offline

Joined: February 14th, 2005, 4:05 pm
Posts: 4710
Location: Boulder, CO
Freakkk, your SW is the other extreme: very powerful but large and complex. Here you can see how much you can achieve with only 17 lines of AHK script. If you need something like this, you can put it together in 10 minutes, and it serves the purpose. If you keep adding features you will loose the overview, most of them you don't even remember and never use. Finding the balance is hard.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 25th, 2005, 3:58 am 
Offline

Joined: July 29th, 2005, 5:32 pm
Posts: 179
Thanks (..I think). Actually when I started the script- it was simply to harness some of the basic time saving features of AHK (like sending repetitive keystrokes, mouse movement, running progs/browsing to different web pages..) into a standalone EXE that i could take to work with me and save keystrokes (RSI's a b**ch! :D ). We don't currently have AHK installed at work- & I wouldn't really have time to sit there and code a little 'quickie' script to make it worth it if we did.

Then I found that I was using it quite a bit at home on projects--- setting a hotkey to repetively indent my loops, copying txt from one screen to another, or basically anything that came up where I found myself doing anything repetitive.

Soon after AHK introduced gui features- I realized how much easier it would be to have a nice little window for setting up scripts.. and on the path to creating that- I just kind of added other scripts that I already created (.. its sort of like my utility belt :lol: )

Those shortcut hotkeys I listed above are not necessary to utilize this script.. they are just some of the minor features I have added. Since there is a gui to interface with- its possible to mouse your way through creating simple macros (in other words-- there is no need to remember all those hotkeys I mentioned..). I just thought I'de share.
Let me know if there is something specific that you think I should improve or simplify


--- Thanks for the feedback Laszlo! :D

_________________
.o0[ corey ]0o.


Report this post
Top
 Profile  
Reply with quote  
PostPosted: March 14th, 2006, 9:18 pm 
Offline

Joined: August 6th, 2005, 9:46 pm
Posts: 11
How about making a gui based shortcut key manager in AHK?

I'd like to be able to easily see in one place all of my custom shortcut keys and what they do. Easily be able to set a shortcut key to run a windows shortcut, or program, or web page, or something else.

In fact, it'd be absolutely lovely if we could replace the keys that are never used like the Scroll-Lock key and use it for "Shortcut Lock"ing ...in other words, when its locked (or on) it would enable all of the shortcut keys you've programmed, and can replace any key on the keyboard (other than the shortcut lock key(scroll lock-or whatever)), and when its off it won't let the shortcut keys work so that you can use regular key assignments.

Maybe this is a job for --- Myself.

?

Yeah, so how about it?


Report this post
Top
 Profile  
Reply with quote  
PostPosted: March 14th, 2006, 9:23 pm 
Offline
User avatar

Joined: August 11th, 2004, 1:47 am
Posts: 5347
Location: UK
Sixty-Six wrote:
How about making a gui based shortcut key manager in AHK?
Take a look at this thread.

_________________
GitHubScriptsIronAHK Contact by email not private message.


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Cool
PostPosted: March 15th, 2006, 8:36 pm 
Offline

Joined: August 6th, 2005, 9:46 pm
Posts: 11
Well, that's quite interesting. I'm using it now and I like it, but it disabled my Autohotkey hot keys just like the post said. That's annoying. Is there any way to make an AHK force its hot keys to work?

Or, better yet, if somebody designed a version of this in AHK...

It'd be nice if there was a LIST view for the assigned hot keys too.

I'll look into doing it myself in my spare time because I think this could be really useful for a lot of people.

Jason


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 15th, 2006, 8:49 pm 
Offline

Joined: February 14th, 2005, 4:05 pm
Posts: 4710
Location: Boulder, CO
You can use the AHK command ListHotkeys. If you want to process the info, you can select it, copy to the clipboard and put the list into your own GUI.


Report this post
Top
 Profile  
Reply with quote  
 Post subject: suggestion
PostPosted: June 5th, 2009, 5:35 pm 
This does not seem to to anything for me on Win XP.
What is this hotkey supposed to do? (I tried both original and the shortened version)
;;;Win-Alt-n --> Iconize others and do this

Also a suggestion
--------------------
Please add a key combo to automatically set Win+(1-9) to the same order of windows visible in the taskbar from left to right. That would be amazing!

thanks!


Report this post
Top
  
Reply with quote  
 Post subject: Re: suggestion
PostPosted: June 5th, 2009, 7:25 pm 
Offline

Joined: May 27th, 2007, 9:41 am
Posts: 4999
dv wrote:
Please add a key combo to automatically set Win+(1-9) to the same order of windows visible in the taskbar from left to right.

Try ActivateByNum - Quick task switching with Win+[1,2,...,0]
http://www.autohotkey.com/forum/viewtopic.php?t=41542

_________________
AHK FAQ
TF : Text files & strings lib, TF Forum


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 5th, 2009, 8:29 pm 
Offline

Joined: June 5th, 2009, 6:00 pm
Posts: 23
thanks that works great!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 7th, 2012, 11:22 pm 
The script in the title works really well for me. The shortened one by Laszlo doesn't work as well - it changes window sizes when restoring windows and it doesn't seem to allow reassigning shortcuts. Is there any reason to try to get Laszlo's to work, other than the concern about conflicting window titles?


Report this post
Top
  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 15 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: MSN [Bot], nomissenrojb and 64 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