Skip to content

Instantly share code, notes, and snippets.

@Saibot942
Last active October 11, 2023 07:48
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Saibot942/1698f89506bd608c9852a82dd0645cb4 to your computer and use it in GitHub Desktop.
Save Saibot942/1698f89506bd608c9852a82dd0645cb4 to your computer and use it in GitHub Desktop.
AHK script to reproduce gmail's shortcut keys in Outlook
;*******************************************************************************
; Use gmail shortcut keys in Outlook desktop client
;*******************************************************************************
;
; Version: 2019.06.26
; Updated: for Outlook 2016 by Toby Garcia
; Source: https://gist.github.com/Saibot942/1698f89506bd608c9852a82dd0645cb4
;
; Author: Lowell Heddings (How-To Geek)
; URL: http://lifehacker.com/5175724/.....gmail-keys
; Original script by: Jayp
; Original URL: http://www.ocellated.com/2009/.....t-outlook/
;
;*******************************************************************************
; Version History:
;
; 2019.06.26 - attempting to fix some niggling issues with focus
; 2018.09.19 - updated for Outlook 2016
; Version 3.1 - added delete & spam functionality and enabled move/star funcs
; Version 3.0 - updated by Toby Garcia to work with Outlook 2013
; Version 2.0 - updated by Ty Myrick to work with Outlook 2010
; Version 1.0 - updated by Lowell Heddings
; Version 0.1 - initial set of hotkeys by Jayp
;*******************************************************************************
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetTitleMatchMode 2 ;allow partial match to window titles
;********************
;Hotkeys for Outlook
;********************
;As best I (Ty Myrick) 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, NUIDocumentWindow ;for Outlook 2010, uncomment this line
#IfWinActive, - Outlook ahk_class rctrl_renwnd32, NUIDocumentWindow ;for Outlook 2013, uncomment this line
;#IfWinActive, ahk_class rctrl_renwnd32, NUIDocumentWindow ;if previous fails for Outlook 2013, uncomment this line
;#IfWinActive, class_nn OutlookGrid2, NUIDocumentWindow ;for Outlook 2016, uncomment this line
y::HandleOutlookKeys("^+1", "y") ;archive message using Quick Steps hotkey (ctrl+Shift+1)
+`::HandleOutlookKeys("^+1", "y") ;archive message using Quick Steps hotkey (ctrl+Shift+2)
f::HandleOutlookKeys("^f", "f") ;forwards message
r::HandleOutlookKeys("^r", "r") ;replies to message
a::HandleOutlookKeys("^+r", "a") ;reply all
v::HandleOutlookKeys("^+v", "v") ;move message box
+u::HandleOutlookKeys("^u", "+u") ;marks messages as unread
+i::HandleOutlookKeys("^q", "+i") ;marks messages as read
j::HandleOutlookKeys("{Down}", "j") ;move down in list
+j::HandleOutlookKeys("+{Down}", "+j") ;move down and select next item (to select multiple messages)
k::HandleOutlookKeys("{Up}", "k") ;move up
+k::HandleOutlookKeys("+{Up}", "+k") ;move up and select next item (to select multiple messages)
o::HandleOutlookKeys("^o", "o") ;open message
s::HandleOutlookKeys("{Insert}","s") ;toggle flag (star)
c::HandleOutlookKeys("^n", "c") ;new message
/::HandleOutlookKeys("^e", "/") ;focus search box
.::HandleOutlookKeys("+{F10}", ".") ;Display context menu
l::HandleOutlookKeys("!3", "l") ;categorize message using All Categories hotkey in Quick Access Toolbar (Alt+3)
+3::HandleOutlookKeys("{Delete}", "+3") ;delete selected message(s)
+1::HandleOutlookKeys("!4", "+1") ;Mark message as spam using Block Sender hotkey in Quick Access Toolbar (Alt+4)
;Logic to determine whether to pass Outlook shortcuts or normal key value, depending on context (trying to avoid replacing key value when you actually want the original key, e.g. in the search box or composing an email message).
#IfWinActive
HandleOutlookKeys( specialKey, normalKey )
{
;Activates key only on main outlook window, not messages, tasks, contacts, etc.
;IfWinActive, - Microsoft Outlook ahk_class rctrl_renwnd32, NUIDocumentWindow, , ;for Outlook 2010, uncomment this line
IfWinActive, - Outlook ahk_class rctrl_renwnd32, NUIDocumentWindow, , ;for Outlook 2013, uncomment this line
{
ControlGetFocus currentCtrl, A ;Find out which control in Outlook has focus.
; 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 PreviewWindow1,AfxWndW5,AfxWndW6,EXCEL71,MsoCommandBar1,NetUIHWND1,OlkPicturePreviewer1,OutlookGrid1,OutlookGrid2,OutlookGrid3,paneClassDC1,RichEdit20WPT2,RichEdit20WPT4,RichEdit20WPT5,RICHEDIT50W1,SUPERGRID2,SUPERGRID1,_WwG1
;This list is ridiculous because MS can't seem to send control back to the same ClassNN when the focus changes then returns
ctrlList = Acrobat PreviewWindow1,AfxWndW5,AfxWndW6,EXCEL71,MsoCommandBar1,NetUIHWND1,OlkPicturePreviewer1,OutlookGrid1,OutlookGrid2,OutlookGrid3,paneClassDC1,RICHEDIT50W1,SUPERGRID2,SUPERGRID1,NetUIHWND1,NetUIHWND3,NetUIHWND18,_WwG1
if currentCtrl in %ctrlList%
{
; MsgBox, Control in list.
Send %specialKey%
}
;Allow typing normalKey somewhere else in the main Outlook window. (Like the search field or the folder pane.)
else
{
; MsgBox, Control not in list.
Send %normalKey%
}
}
;Allow typing normalKey in another window type within Outlook, like a mail message, task, appointment, etc.
else
{
Send %normalKey%
}
}
@Saibot942
Copy link
Author

I have been maintaining this AHK script to enable gmail's shortcut keys in Outlook, since 2010. It's mostly compatible with Outlook 2016 now, but has an annoying bug where typing doesn't work as expected within the outlook preview pain after it loses focus. At that point you can either pop-out the compose window or cancel and start again.

@Saibot942
Copy link
Author

Saibot942 commented Sep 19, 2018

y -- archive message using Quick Steps hotkey (ctrl+Shift+1)
f -- forward message
r -- replies to message
a -- reply all
Shift+u -- mark unread
Shift+i -- mark read
j -- move down in list
Shift+j -- move down and select next item
k -- move up
Shift+k -- move up and select next item
o -- open message
s -- toggle flag (star)
c -- new message
/ -- focus search box
. -- Display context menu
l -- categorize message using All Categories hotkey in Quick Access Toolbar (Alt+3)
# -- delete selected message(s)
!-- Mark message as spam using Block Sender hotkey in Quick Access Toolbar (Alt+4)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment