AutoHotkey Community

It is currently May 25th, 2012, 1:44 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 154 posts ]  Go to page Previous  1 ... 7, 8, 9, 10, 11  Next
Author Message
 Post subject: Capslock co-existance
PostPosted: April 18th, 2007, 5:53 am 
Offline

Joined: April 18th, 2007, 5:47 am
Posts: 2
I'm one of those (apparently) rare folks that actually does use Capslock occasionally.

This is a great script and Capslock is the best hotkey IMHO, however it would be nice if pressing it again while the window-switcher is up closed it and actually enabled Capslock.

I'm going to look over the code and see if I can add that. If so I'll post it up.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 19th, 2007, 6:51 am 
Offline

Joined: April 18th, 2007, 5:47 am
Posts: 2
Ok, I did some reading and figured out how to implement having capslock close the window and toggle the capslock state. It didn't turn out as nicely as I'd thought however.

The better method is to have capslock open and close the window, while having Control-Capslock toggle the capslock state. The code, added just above the original Capslock:: definition (around line 160) is:

Code:
; If we're already in the Window Switcher interface, hitting Capslock gets us back out
#IfWinActive Window Switcher ahk_class AutoHotkeyGUI
Capslock::
   Send {Esc}
return
#IfWinActive

; Ctrl-Capslock toggles the Capslock state
Control & CapsLock::
   GetKeyState CapsLockState, CapsLock, T
   IfEqual CapsLockState,D, SetCapslockState AlwaysOff
   Else SetCapslockState AlwaysOn
Return

;----------------------------------------------------------------------
;
; I never use the CapsLock key, that's why I chose it.
;
CapsLock::


In case you're curious, the code for the original idea is:

Code:
; If we're already in the Window Switcher interface, hitting Capslock gets us back out and toggles the Capslock state
#IfWinActive Window Switcher ahk_class AutoHotkeyGUI
Capslock::
   Send {Esc}
   GetKeyState CapsLockState, CapsLock, T
   IfEqual CapsLockState,D, SetCapslockState AlwaysOff
   Else SetCapslockState AlwaysOn
return
#IfWinActive

;----------------------------------------------------------------------
;
; I never use the CapsLock key, that's why I chose it.
;
CapsLock::


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 21st, 2007, 10:03 am 
Offline

Joined: June 4th, 2005, 1:54 am
Posts: 146
Is there any way for me to change the font size in the listbox?


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Cool script!
PostPosted: August 23rd, 2007, 7:39 am 
Offline

Joined: June 14th, 2006, 7:49 am
Posts: 3
Very usefull, thanx!

Did change the hotkey to WIN + Capslock, though.. ;)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 25th, 2007, 12:30 pm 
Could you make it so if the user presses caps lock (or whatever the hotkey they prefer is) whilst the window is active, it hides itself?


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: November 8th, 2007, 12:05 am 
Offline

Joined: November 7th, 2007, 10:44 pm
Posts: 6
Hi,

Is there a way that we can modified the code so that it will alt+tab automatically every 30 second or 1 minute

say you got a web page monitor and another monitoring system n you just need those 2 to alt+tab but not the any other application that you have open is this possible?

Regards,
Huy


Report this post
Top
 Profile  
Reply with quote  
 Post subject: CapsLock Toggle
PostPosted: November 9th, 2007, 9:40 pm 
Offline

Joined: April 6th, 2007, 5:16 pm
Posts: 12
In case anyone missed it..

Seren posted a way to have the CapsLock show/hide the window list. It only takes about 5 seconds to modify the script, and it works great.

_________________
~ Eric D. Burdo


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 2nd, 2008, 1:16 am 
Awesome! It's been about three minutes and I'm already dreading using a computer that doesn't have this program. Thanks a bunch for making & sharing it.


Report this post
Top
  
Reply with quote  
 Post subject: *gasp*
PostPosted: March 13th, 2008, 3:20 pm 
Offline

Joined: September 24th, 2004, 5:10 am
Posts: 32
keyboardfreak, I hate you!

I have been wanting to code something like that for a while but never got to it until today. I came home and immediately wanted to start coding but decided to check the forum first, in case someone has already invented the wheel, and found your script! You took away the hours of fun that I was about to have! I hate you!

Having got that out of my system, ahem, I just want to say THANKS. :)

Thanks for sharing such a great script with us, and saving me hours of coding time. It's great not having to reinvent the wheel. I like your wheel. Neat!

:D


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 15th, 2008, 8:15 am 
a great addition to this is if we could integrate the search behavior of the script 320mph here.

so to switch to the next task, one would just need to type any word/s in a specific window title in any order.

a title such as this

Notepad2 - Sample Window

can be matched by typing

"d2 ample"

or

"note win"

zooming in on a particular window title would be so much easier.

if only I knew how to do it.


Report this post
Top
  
Reply with quote  
PostPosted: March 15th, 2008, 9:02 pm 
@_adam: I did create the kind of search behavior that you were looking for. The different strings to look for are separated by a space.
I might have broken some of the other features along the way, but I'm providing my version as is, so you can grab it and modify it as you see fit.

Code:
;
; iswitchw - Incrementally switch between windows using substrings
;
; Required AutoHotkey version: 1.0.25+
;
; When this script is triggered via its hotkey the list of titles of
; all visible windows appears. The list can be narrowed quickly to a
; particular window by typing a substring of a window title.
;
; When the list is narrowed the desired window can be selected using
; the cursor keys and Enter. If the substring matches exactly one
; window that window is activated immediately (configurable, see the
; "autoactivateifonlyone" variable).
;
; The window selection can be cancelled with Esc.
;
; The switcher window can be moved horizontally with the left/right
; arrow keys if it blocks the view of windows under it.
;
; The switcher can also be operated with the mouse, although it is
; meant to be used from the keyboard. A mouse click activates the
; currently selected window. Mouse users may want to change the
; activation key to one of the mouse keys.
;
; If enabled possible completions are offered when the same unique
; substring is found in the title of more than one window.
;
; For example, the user typed the string "co" and the list is
; narrowed to two windows: "Windows Commander" and "Command Prompt".
; In this case the "command" substring can be completed automatically,
; so the script offers this completion in square brackets which the
; user can accept with the TAB key:
;
;     co[mmand]
;
; This feature can be confusing for novice users, so it is disabled
; by default.
;
;
; For the idea of this script the credit goes to the creators of the
; iswitchb package for the Emacs editor
;
;
;----------------------------------------------------------------------
;
; User configuration
;

; set this to yes if you want to select the only matching window
; automatically
autoactivateifonlyone =

; set this to yes if you want to enable tab completion (see above)
; it has no effect if firstlettermatch (see below) is enabled
tabcompletion =

; set this to yes to enable digit shortcuts when there are ten or
; less items in the list
digitshortcuts =

; set this to yes to enable activating the currently selected
; window in the background
activateselectioninbg =

; number of milliseconds to wait for the user become idle, before
; activating the currently selected window in the background
;
; it has no effect if activateselectioninbg is off
;
; if set to blank the current selection is activated immediately
; without delay
bgactivationdelay = 300

; show process name before window title.
showprocessname =

; Close switcher window if the user activates an other window.
; It does not work well if activateselectioninbg is enabled, so
; currently they cannot be enabled together.
closeifinactivated =

if activateselectioninbg <>
    if closeifinactivated <>
    {
        msgbox, activateselectioninbg and closeifinactivated cannot be enabled together
        exitapp
    }

; List of subtsrings separated with pipe (|) characters (e.g. carpe|diem).
; Window titles containing any of the listed substrings are filtered out
; from the list of windows.
filterlist =

; Set this yes to update the list of windows every time the contents of the
; listbox is updated. This is usually not necessary and it is an overhead which
; slows down the update of the listbox, so this feature is disabled by default.
dynamicwindowlist =

; path to sound file played when the user types a substring which
; does not match any of the windows
;
; set this to blank if you don't want a sound
;
nomatchsound = 

if nomatchsound <>
    ifnotexist, %nomatchsound%
        msgbox, Sound file %nomatchsound% not found. No sound will be played.

;----------------------------------------------------------------------
;
; Global variables
;
;     numallwin      - the number of windows on the desktop
;     allwinarray    - array containing the titles of windows on the desktop
;                      dynamicwindowlist is disabled
;     allwinidarray  - window ids corresponding to the titles in allwinarray
;     numwin         - the number of windows in the listbox
;     idarray        - array containing window ids for the listbox items
;     orig_active_id - the window ID of the originally active window
;                      (when the switcher is activated)
;     prev_active_id - the window ID of the last window activated in the
;                      background (only if activateselectioninbg is enabled)
;     switcher_id    - the window ID of the switcher window
;     filters        - array of filters for filtering out titles
;                      from the window list
;
;----------------------------------------------------------------------

AutoTrim, off

Gui, Add, ListBox, vindex gListBoxClick x6 y11 w450 h250 AltSubmit
Gui, Add, Text, x6 y260 w50 h20, Search`:
Gui, Add, Edit, x46 y257 w410 h20,

if filterlist <>
{
    loop, parse, filterlist, |
    {
        filters%a_index% = %A_LoopField%
    }
}


; If we're already in the Window Switcher interface, hitting Capslock gets us back out
#IfWinActive Window Switcher ahk_class AutoHotkeyGUI
Capslock::
   Send {Esc}
return
#IfWinActive

;----------------------------------------------------------------------
;
; I never use the CapsLock key, that's why I chose it.
;
CapsLock::

search =
numallwin = 0
GuiControl,, Edit1
GoSub, RefreshWindowList

WinGet, orig_active_id, ID, A
prev_active_id = %orig_active_id%

Gui, Show, Center h284 w461, Window Switcher

; If we determine the ID of the switcher window here then
; why doesn't it appear in the window list when the script is
; run the first time? (Note that RefreshWindowList has already
; been called above).
; Answer: Because when this code runs first the switcher window
; does not exist yet when RefreshWindowList is called.
WinGet, switcher_id, ID, A
WinSet, AlwaysOnTop, On, ahk_id %switcher_id%

Loop
{
    if closeifinactivated <>
        settimer, CloseIfInactive, 200

    Input, input, L1, {enter}{esc}{backspace}{up}{down}{pgup}{pgdn}{tab}{Left}{right}

    if closeifinactivated <>
        settimer, CloseIfInactive, off

    if ErrorLevel = EndKey:enter
    {
        GoSub, ActivateWindow
        break
    }

    if ErrorLevel = EndKey:escape
    {
        Gui, cancel

        ; restore the originally active window if
        ; activateselectioninbg is enabled
        if activateselectioninbg <>
            WinActivate, ahk_id %orig_active_id%

        break
    }

    if ErrorLevel = EndKey:backspace
    {
        GoSub, DeleteSearchChar
        continue
    }

    if ErrorLevel = EndKey:tab
        if completion =
            continue
        else
            input = %completion%

    ; pass these keys to the selector window

    if ErrorLevel = EndKey:up
    {
        Send, {up}
        GoSuB ActivateWindowInBackgroundIfEnabled
        continue
    }

    if ErrorLevel = EndKey:down
    {
        Send, {down}
        GoSuB ActivateWindowInBackgroundIfEnabled
        continue
    }

    if ErrorLevel = EndKey:pgup
    {
        Send, {pgup}
        GoSuB ActivateWindowInBackgroundIfEnabled
        continue
    }

    if ErrorLevel = EndKey:pgdn
    {
        Send, {pgdn}
        GoSuB ActivateWindowInBackgroundIfEnabled
        continue
    }

    if ErrorLevel = EndKey:left
    {
        direction = -1
        GoSuB MoveSwitcher
        continue
    }

    if ErrorLevel = EndKey:right
    {
        direction = 1
        GoSuB MoveSwitcher
        continue
    }


    ; FIXME: probably other error level cases
    ; should be handled here (interruption?)

    ; invoke digit shortcuts if applicable
    if digitshortcuts <>
        if numwin <= 10
            if input in 1,2,3,4,5,6,7,8,9,0
            {
                if input = 0
                    input = 10

                if numwin < %input%
                {
                    if nomatchsound <>
                        SoundPlay, %nomatchsound%
                    continue
                }

                GuiControl, choose, ListBox1, %input%
                GoSub, ActivateWindow
                break
            }

    ; process typed character

    search = %search%%input%
    GuiControl,, Edit1, %search%
    GoSub, RefreshWindowList
}

Gosub, CleanExit

return

;----------------------------------------------------------------------
;
; Refresh the list of windows according to the search criteria
;
; Sets: numwin  - see the documentation of global variables
;       idarray - see the documentation of global variables
;
RefreshWindowList:
    ; refresh the list of windows if necessary

    if ( dynamicwindowlist = "yes" or numallwin = 0 )
    {
        numallwin = 0

        WinGet, id, list, , , Program Manager
        Loop, %id%
        {
            StringTrimRight, this_id, id%a_index%, 0
            WinGetTitle, title, ahk_id %this_id%

            ; FIXME: windows with empty titles?
            if title =
                continue

            ; don't add the switcher window
            if switcher_id = %this_id%
                continue

            ; show process name if enabled
            if showprocessname <>
            {
                WinGet, procname, ProcessName, ahk_id %this_id%

                stringgetpos, pos, procname, .
                if ErrorLevel <> 1
                {
                    stringleft, procname, procname, %pos%
                }

                stringupper, procname, procname
                title = %procname%: %title%
            }

            ; don't add titles which match any of the filters
            if filterlist <>
            {
                filtered =

                loop
                {
                    stringtrimright, filter, filters%a_index%, 0
                    if filter =
                      break
                    else
                        ifinstring, title, %filter%
                        {
                           filtered = yes
                           break
                        }
                }

                if filtered = yes
                    continue
            }

            ; replace pipe (|) characters in the window title,
            ; because Gui Add uses it for separating listbox items
            StringReplace, title, title, |, -, all

            numallwin += 1
            allwinarray%numallwin% = %title%
            allwinidarray%numallwin% = %this_id%
        }
    }

    ; filter the window list according to the search criteria

    winlist =
    numwin = 0

    Loop, %numallwin%
    {
        StringTrimRight, title, allwinarray%a_index%, 0
        StringTrimRight, this_id, allwinidarray%a_index%, 0

        ; don't add the windows not matching the search string
        ; if there is a search string
        if search <>
        {
            ;split searchString into groups
               StringSplit, splitArray, search, %a_space%
               
               stillMatch = 1 ; flag used to indicate if all substrings matched
               Loop, %splitArray0%
               {
                  subString:=splitArray%a_index%
                  If subString != %a_space%
                  {
                     IfNotInString, title, %subString%
                     {
                        stillMatch=0
                        Break
                     }
                  }
               }
               If stillMatch=0
               {
                  Continue
               }
             }

        if winlist <>
            winlist = %winlist%|
        winlist = %winlist%%title%`r%this_id%

        numwin += 1
        winarray%numwin% = %title%
    }

    ; if the pattern didn't match any window
    if numwin = 0
        ; if the search string is empty then we can't do much
        if search =
        {
            Gui, cancel
            Gosub, CleanExit
        }
        ; delete the last character
        else
        {
            if nomatchsound <>
                SoundPlay, %nomatchsound%

            GoSub, DeleteSearchChar
            return
        }

    ; sort the list alphabetically
    Sort, winlist, D|

    ; add digit shortcuts if there are ten or less windows
    ; in the list and digit shortcuts are enabled
    if digitshortcuts <>
        if numwin <= 10
        {
            digitlist =
            digit = 1
            loop, parse, winlist, |
            {
                ; FIXME: windows with empty title?
                if A_LoopField <>
                {
                    if digitlist <>
                        digitlist = %digitlist%|
                    digitlist = %digitlist%%digit%%A_Space%%A_Space%%A_Space%%A_LoopField%

                    digit += 1
                    if digit = 10
                        digit = 0
                }
            }
            winlist = %digitlist%
        }

    ; strip window IDs from the sorted list
    titlelist =
    arrayindex = 1

    loop, parse, winlist, |
    {
        stringgetpos, pos, A_LoopField, `r

        stringleft, title, A_LoopField, %pos%
        titlelist = %titlelist%|%title%

        pos += 2 ; skip the separator char
        stringmid, id, A_LoopField, %pos%, 10000
        idarray%arrayindex% = %id%
        ++arrayindex
    }

    ; show the list
    GuiControl,, ListBox1, %titlelist%
    GuiControl, Choose, ListBox1, 1

    if numwin = 1
        if autoactivateifonlyone <>
        {
            GoSub, ActivateWindow
            Gosub, CleanExit
        }

    GoSub ActivateWindowInBackgroundIfEnabled

    completion =

    if tabcompletion =
        return

    ; completion is not implemented for first letter match mode
    if firstlettermatch <>
        return

    ; determine possible completion if there is
    ; a search string and there are more than one
    ; window in the list

    if search =
        return
   
    if numwin = 1
        return

    loop
    {
        nextchar =

        loop, %numwin%
        {
            stringtrimleft, title, winarray%a_index%, 0

            if nextchar =
            {
                substr = %search%%completion%
                stringlen, substr_len, substr
                stringgetpos, pos, title, %substr%

                if pos = -1
                    break

                pos += %substr_len%

                ; if the substring matches the end of the
                ; string then no more characters can be completed
                stringlen, title_len, title
                if pos >= %title_len%
                {
                    pos = -1
                    break
                }

                ; stringmid has different position semantics
                ; than stringgetpos. strange...
                pos += 1
                stringmid, nextchar, title, %pos%, 1
                substr = %substr%%nextchar%
             }
             else
             {
                stringgetpos, pos, title, %substr%
                if pos = -1
                    break
             }
        }

        if pos = -1
            break
        else
            completion = %completion%%nextchar%
    }

    if completion <>
        GuiControl,, Edit1, %search%[%completion%]

return

;----------------------------------------------------------------------
;
; Delete last search char and update the window list
;
DeleteSearchChar:

if search =
    return

StringTrimRight, search, search, 1
GuiControl,, Edit1, %search%
GoSub, RefreshWindowList

return

;----------------------------------------------------------------------
;
; Activate selected window
;
ActivateWindow:

Gui, submit
stringtrimleft, window_id, idarray%index%, 0
WinActivate, ahk_id %window_id%

return

;----------------------------------------------------------------------
;
; Activate selected window in the background
;
ActivateWindowInBackground:

guicontrolget, index,, ListBox1
stringtrimleft, window_id, idarray%index%, 0

if prev_active_id <> %window_id%
{
    WinActivate, ahk_id %window_id%
    WinActivate, ahk_id %switcher_id%
    prev_active_id = %window_id%
}

return

;----------------------------------------------------------------------
;
; Activate selected window in the background if the option is enabled.
; If an activation delay is set then a timer is started instead of
; activating the window immediately.
;
ActivateWindowInBackgroundIfEnabled:

if activateselectioninbg =
    return

; Don't do it just after the switcher is activated. It is confusing
; if active window is changed immediately.
WinGet, id, ID, ahk_id %switcher_id%
if id =
    return

if bgactivationdelay =
    GoSub ActivateWindowInBackground
else
    settimer, BgActivationTimer, %bgactivationdelay%

return

;----------------------------------------------------------------------
;
; Check if the user is idle and if so activate the currently selected
; window in the background
;
BgActivationTimer:

settimer, BgActivationTimer, off

GoSub ActivateWindowInBackground

return

;----------------------------------------------------------------------
;
; Stop background window activation timer if necessary and exit
;
CleanExit:

settimer, BgActivationTimer, off

exit

;----------------------------------------------------------------------
;
; Cancel keyboard input if GUI is closed.
;
GuiClose:

send, {esc}

return

;----------------------------------------------------------------------
;
; Handle mouse click events on the list box
;
ListBoxClick:
if (A_GuiControlEvent = "Normal"
    and !GetKeyState("Down", "P") and !GetKeyState("Up", "P"))
    send, {enter}
return

;----------------------------------------------------------------------
;
; Move switcher window horizontally
;
; Input: direction - 1 for right, -1 for left
;
MoveSwitcher:

direction *= 100
WinGetPos, x, y, width, , ahk_id %switcher_id%
x += %direction%

if x < 0
    x = 0
else
{
   SysGet screensize, MonitorWorkArea
   screensizeRight -= %width%
   if x > %screensizeRight%
      x = %screensizeRight%
}

prevdelay = %A_WinDelay%
SetWinDelay, -1
WinMove, ahk_id %switcher_id%, , %x%, %y%
SetWinDelay, %prevdelay%

return

;----------------------------------------------------------------------
;
; Close the switcher window if the user activated an other window
;
CloseIfInactive:

IfWinNotActive, ahk_id %switcher_id%
    send, {esc}

Return


Report this post
Top
  
Reply with quote  
PostPosted: March 16th, 2008, 6:31 am 
hjoerdis wrote:
@_adam: I did create the kind of search behavior that you were looking for. The different strings to look for are separated by a space.
I might have broken some of the other features along the way, but I'm providing my version as is, so you can grab it and modify it as you see fit.


oh wow, that's just perfect. it's working well, and with this kind of search behavior, I won't be needing the other features (such as completion etc)

thank you for posting this. it's beautiful. 8)


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: March 16th, 2008, 10:04 am 
Offline

Joined: September 24th, 2004, 5:10 am
Posts: 32
For those who want to BlockInput immediately after switching to the selected window so that excessive keys will not be sent to it, you can use the modified code for ActivateWindow below:

Code:
;----------------------------------------------------------------------
;
; Activate selected window
;
ActivateWindow:

BlockInput, on
ToolTip, :)

Gui, submit
stringtrimleft, window_id, idarray%index%, 0
WinActivate, ahk_id %window_id%

Loop
{
  If (A_TimeIdlePhysical < 300)
    Sleep 100
  Else
    Break
}

BlockInput, off
ToolTip

return


This allows you to just type away without having to worry about sending extra keys to the window, especially if the window is an editor. :)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 27th, 2008, 5:46 pm 
Offline

Joined: December 6th, 2007, 4:21 pm
Posts: 32
Thanks, Phi, for your modified code! As soon as I started using this script, I realized that the extra keys being sent might end up being a problem. But before I had to even think of how to solve it, I found your solution.

:D


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 26th, 2008, 10:33 pm 
great script


Report this post
Top
  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 154 posts ]  Go to page Previous  1 ... 7, 8, 9, 10, 11  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 20 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