AutoHotkey Community

It is currently May 26th, 2012, 12:23 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: September 10th, 2008, 11:34 pm 
Hi all,

Here is a script I bashed up that allows me to use ALT+F1 to F12 to select open windows.

I wanted this so that with fullscreen PuTTY sessions I could emulate being back on the Linux console, where swapping between terminals used the afformentioned quick keystrokes!

It is also quite handy for quickly switching between windows, as I loathe using ALT-TAB.


There are 2 disadvantages however:

- ALT+F4 is remapped by the above (You could change these keys to Ctrl+F1 etc if you wanted, but I dont care...)

- The window order is determined by the window ID, which are a bit random, and thus not in the same order as they are on the taskbar, so it takes a bit of guessing to find out which button brings up which window.

(-- Does anyone know how the open windows on the taskbar are sorted by? That would be much nicer...)


Thanks for Autohotkey, its the bomb!

-Joe

P.S. If anyone knows a better way or sorting arrays than throwing them in and out of strings, let me know. Ditto for the array access during function call business.

--- Code ----

Code:
SwitchWindow(n) {

    ; Get open Window ID list
    ; then activate specific window.

    WinGet, idlist, List

    if idlist < %n%
    {
        Return    ; Abort if not enough windows open
    }

    Loop %idlist%
    {
   temp := idlist%A_Index%
        idstrlist = %temp%,%idstrlist%
    }

    Sort, idstrlist, N D,
    StringSplit, idlist, idstrlist, `,

    temp := idlist%n%
    WinActivate, ahk_id %temp%
    return
}


!F1::
SwitchWindow(1)
return

!F2::
SwitchWindow(2)
return

!F3::
SwitchWindow(3)
return

!F4::
SwitchWindow(4)
return

!F5::
SwitchWindow(5)
return

!F6::
SwitchWindow(6)
return

!F7::
SwitchWindow(7)
return

!F8::
SwitchWindow(8)
return

!F9::
SwitchWindow(9)
return

!F10::
SwitchWindow(10)
return

!F11::
SwitchWindow(11)
return

!F12::
SwitchWindow(12)
return


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: September 12th, 2008, 11:46 pm 
Offline

Joined: September 12th, 2008, 8:24 pm
Posts: 2
Location: South Africa
hi, firstly very nice script :), i always have lots of windows open.

i have a request though, i wouldn't know how to do it myself as i'm quite new to this, anyway my request:

if i press say ctrl+alt+fx where x could be 1..12 (12 function keys) i want it to assign that fx to the current window so that if i press alt+fx (same x) later (when the window is now not current) it will select the window. i hope u understand what i mean

thanks


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 18th, 2008, 6:02 pm 
Pretty good idea.

Here then is a script that allows you to bind a window with Ctrl+Fn and raise it later with Alt+Fn.

If you want to be able to bind the window with Ctrl+Alt+Fn as you suggested, then modify the lines that look like ^F12:: to look like ^!F12::

Code:
; Bindable ALT+Fn Window selector - josephusm
;
; Use Ctrl+Fn to bind the active window, and Alt+Fn to raise it later
;

Loop, 12
{
    id%A_Index% := 0
}
return

RemoveToolTip:
SetTimer, RemoveToolTip, Off
ToolTip
return

BindKey(key)
{
    ; Store the active window's ID

    WinGet, active_id, ID, A
    id%key% := active_id

    ToolTip, %key%
    SetTimer, RemoveToolTip, 1000
   
    return
}

UseBind(key)
{
    ; Use the stored window's ID to focus it
    ; if it still exists

    win_id := id%key%

    if WinExist("ahk_id" . win_id)
    {
        WinActivate, ahk_id %win_id%

        ToolTip, %key%
        SetTimer, RemoveToolTip, 500
    }
    else
    {
        ToolTip, %key%: No existing window bound
        SetTimer, RemoveToolTip, 1000
    }

    return
}


^F1::
BindKey(1)
return

!F1::
UseBind(1)
return

^F2::
BindKey(2)
return

!F2::
UseBind(2)
return

^F3::
BindKey(3)
return

!F3::
UseBind(3)
return

^F4::
BindKey(4)
return

!F4::
UseBind(4)
return

^F5::
BindKey(5)
return

!F5::
UseBind(5)
return

^F6::
BindKey(6)
return

!F6::
UseBind(6)
return

^F7::
BindKey(7)
return

!F7::
UseBind(7)
return

^F8::
BindKey(8)
return

!F8::
UseBind(8)
return


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: September 19th, 2008, 9:08 am 
Offline

Joined: September 12th, 2008, 8:24 pm
Posts: 2
Location: South Africa
thanks, this is great :D

although i disabled the alt-f4 (for closing windows) and ctrl-f2 (for bookmarks in notepad++)

now i've gotta try and figure out your code (the top bits especially) :P


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

All times are UTC [ DST ]


Who is online

Users browsing this forum: bbwht, Exabot [Bot], MSN [Bot], oldbrother and 46 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