Skip to content

Instantly share code, notes, and snippets.

@adamsmith
Created August 27, 2012 02:31

Revisions

  1. adamsmith created this gist Aug 27, 2012.
    69 changes: 69 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,69 @@
    ; in Outlook, a -> Archive, r -> Reply, f -> Forward, n -> New
    ; derived from http://www.autohotkey.com/community/viewtopic.php?t=41790

    ; Note: set up Ctrl + Shift + 1 to be 'Archive' as a Quick Step for the shortcut to work


    SendMode Input ; superior speed and reliability.
    SetTitleMatchMode 2 ;allow partial match to window titles

    ;********************
    ;Hotkeys for Outlook
    ;********************

    ;As best I can tell, the window text 'NUIDocumentWindow' is not present
    ;on any other items except the main window. Also, I look for the phrase
    ; ' - Microsoft Outlook' in the title, which will not appear in the title (unless
    ;a user types this string into the subject of a message or task).
    ;#IfWinActive - Microsoft Outlook ahk_class rctrl_renwnd32
    #IfWinActive Microsoft Outlook ahk_class rctrl_renwnd32
    a::HandleOutlookKeys("^+1", "a") ;calls archive quick action
    r::HandleOutlookKeys("^+r", "r") ;replies all to message
    f::HandleOutlookKeys("^f", "f") ;forwards message
    n::HandleOutlookKeys("^n", "n") ;new message
    #IfWinActive

    ;Passes Outlook a special key combination for custom keystrokes or normal key value, depending on

    context
    HandleOutlookKeys( specialKey, normalKey ) {

    ;Activates key only on main outlook window, not messages, tasks, contacts, etc.
    If WinActive("ahk_class" . "rctrl_renwnd32") and WinActive("Microsoft Outlook")
    {
    ;Find out which control in Outlook has focus
    ControlGetFocus, currentCtrl
    ;MsgBox, Control with focus = %currentCtrl%

    ;set list of controls that should respond to specialKey. Controls are the list of emails and the

    main (and minor) controls of the reading pane, including controls when viewing certain attachments.
    ;Currently I handle archiving when viewing attachments of Word, Excel, Powerpoint, Text, jpgs,

    pdfs
    ;The control 'RichEdit20WPT1' (email subject line) is used extensively for inline editing. Thus

    it had to be removed. If an email's subject has focus, it won't archive...
    ctrlList = Acrobat Preview

    Window1,AfxWndW5,AfxWndW6,EXCEL71,MsoCommandBar1,OlkPicturePreviewer1,paneClassDC1,RichEdit20WPT2,RichEdit

    20WPT4,RichEdit20WPT5,RICHEDIT50W1,SUPERGRID1,SUPERGRID2,_WwG1

    if currentCtrl in %ctrlList%
    {
    Send %specialKey%
    ;Allow typing normalKey somewhere else in the main Outlook window. (Like the search field or the

    folder pane.)
    } else {
    Send %normalKey%
    }

    ;Allow typing normalKey in another window type within Outlook, like a mail message, task,

    appointment, etc.
    } else {
    Send %normalKey%
    }
    }