SuperEsc: SetKeyDelay, -1

SuperEsc: SetKeyDelay, -1

;=====================================================================o
;                      Esc Enhancement                                |
;---------------------------------------------------------------------o
;Description:                                                         |
;    This Script turns Esc into an function Key just like Ctrl and    |
; Alt by combining Esc with almost all other keys in the keyboard.    |
;                                                                     |
; See also:                                                           |
;    github.com/Vonng/Configuration/blob/master/win_ahk/CapsLock.ahk  |
;                                                                     |
;Summary:                                                             |
;o----------------------o---------------------------------------------o
;|Esc + `             | {CapsLock}CapsLock Switcher as a Substituent  |
;|Esc + {BackSpace}   | Exit                                          |
;|Esc + hjklwb        | Vim-Style Cursor Mover                        |
;|Esc + ioup          | Convient Home/End PageUp/PageDn               |
;|Esc + nm,.          | Convient Delete Controller                    |
;|Esc + zxcvay        | Windows-Style Editor                          |
;|Esc + Direction     | Mouse Move                                    |
;|Esc + Enter         | Mouse Click                                   |
;|Esc + {F1}~{F6}     | Media Controller                              |
;|Esc + qsd           | Windows & Tags Control                        |
;|Esc + ;'            | Convient Key Mapping                          |
;-----------------------o---------------------------------------------o
;|Use it whatever and wherever you like. Hope it help                 |
;=====================================================================o

;=====================================================================o
#NoTrayIcon                                                          ;|
#SingleInstance force                                                ;|
SetKeyDelay, -1                                                      ;|
                                                                     ;|
$Esc:: Send, {ESC}                                                   ;|
$^+Esc:: Send, ^+{Esc}                                               ;|
$#Esc:: ExitApp                                                      ;|
;=====================================================================o

;=====================================================================o
;                       CapsLock Switcher:                           ;|
;---------------------------------o-----------------------------------o
;                      Esc + ` | {CapsLock}                          ;|
;---------------------------------o-----------------------------------o
Esc & `::                                                            ;|
GetKeyState, CapsLockState, CapsLock, T                              ;|
if CapsLockState = D                                                 ;|
    SetCapsLockState, AlwaysOff                                      ;|
else                                                                 ;|
    SetCapsLockState, AlwaysOn                                       ;|
KeyWait, ``                                                          ;|
return                                                               ;|
;---------------------------------------------------------------------o

;=====================================================================o
;                     Esc Direction Navigator                        ;|
;-----------------------------------o---------------------------------o
;                        Esc + h |  Left                             ;|
;                        Esc + j |  Down                             ;|
;                        Esc + k |  Up                               ;|
;                        Esc + l |  Right                            ;|
;-----------------------------------o---------------------------------o
Esc & h::Send, {Left}                                                ;|
Esc & j::Send, {Down}                                                ;|
Esc & k::Send, {Up}                                                  ;|
Esc & l::Send, {Right}                                               ;|
;---------------------------------------------------------------------o

;=====================================================================o
;                       Esc Home/End Navigator                       ;|
;-----------------------------------o---------------------------------o
;                         Esc + i |  Home                            ;|
;                         Esc + o |  End                             ;|
;                      Ctrl, Alt Compatible                          ;|
;-----------------------------------o---------------------------------o
Esc & i::                                                            ;|
if GetKeyState("control") = 0                                        ;|
{                                                                    ;|
    if GetKeyState("alt") = 0                                        ;|
        Send, {Home}                                                 ;|
    else                                                             ;|
        Send, +{Home}                                                ;|
    return                                                           ;|
}                                                                    ;|
else {                                                               ;|
    if GetKeyState("alt") = 0                                        ;|
        Send, ^{Home}                                                ;|
    else                                                             ;|
        Send, +^{Home}                                               ;|
    return                                                           ;|
}                                                                    ;|
return                                                               ;|
;-----------------------------------o                                ;|
Esc & o::                                                            ;|
if GetKeyState("control") = 0                                        ;|
{                                                                    ;|
    if GetKeyState("alt") = 0                                        ;|
        Send, {End}                                                  ;|
    else                                                             ;|
        Send, +{End}                                                 ;|
    return                                                           ;|
}                                                                    ;|
else {                                                               ;|
    if GetKeyState("alt") = 0                                        ;|
        Send, ^{End}                                                 ;|
    else                                                             ;|
        Send, +^{End}                                                ;|
    return                                                           ;|
}                                                                    ;|
return                                                               ;|
;---------------------------------------------------------------------o

;=====================================================================o
;                        Esc Page Navigator                          ;|
;-----------------------------------o---------------------------------o
;                        Esc + u |  PageUp                           ;|
;                        Esc + p |  PageDown                         ;|
;                        Ctrl, Alt Compatible                        ;|
;-----------------------------------o---------------------------------o
Esc & u::                                                            ;|
if GetKeyState("control") = 0                                        ;|
{                                                                    ;|
    if GetKeyState("alt") = 0                                        ;|
        Send, {PgUp}                                                 ;|
    else                                                             ;|
        Send, +{PgUp}                                                ;|
    return                                                           ;|
}                                                                    ;|
else {                                                               ;|
    if GetKeyState("alt") = 0                                        ;|
        Send, ^{PgUp}                                                ;|
    else                                                             ;|
        Send, +^{PgUp}                                               ;|
    return                                                           ;|
}                                                                    ;|
return                                                               ;|
;-----------------------------------o                                ;|
Esc & p::                                                            ;|
if GetKeyState("control") = 0                                        ;|
{                                                                    ;|
    if GetKeyState("alt") = 0                                        ;|
        Send, {PgDn}                                                 ;|
    else                                                             ;|
        Send, +{PgDn}                                                ;|
    return                                                           ;|
}                                                                    ;|
else {                                                               ;|
    if GetKeyState("alt") = 0                                        ;|
        Send, ^{PgDn}                                                ;|
    else                                                             ;|
        Send, +^{PgDn}                                               ;|
    return                                                           ;|
}                                                                    ;|
return                                                               ;|
;---------------------------------------------------------------------o

;=====================================================================o
;                        Esc Mouse Controller                        ;|
;-----------------------------------o---------------------------------o
;                       Esc + Up   |  Mouse Up                       ;|
;                       Esc + Down |  Mouse Down                     ;|
;                       Esc + Left |  Mouse Left                     ;|
;                      Esc + Right |  Mouse Right                    ;|
;        Esc + Enter(Push Release) |  Mouse Left Push(Release)       ;|
;-----------------------------------o---------------------------------o
Esc & Up::    MouseMove, 0, -10, 0, R                                ;|
Esc & Down::  MouseMove, 0, 10, 0, R                                 ;|
Esc & Left::  MouseMove, -10, 0, 0, R                                ;|
Esc & Right:: MouseMove, 10, 0, 0, R                                 ;|
;-----------------------------------o                                ;|
Esc & Enter::                                                        ;|
SendEvent {Blind}{LButton down}                                      ;|
KeyWait Enter                                                        ;|
SendEvent {Blind}{LButton up}                                        ;|
return                                                               ;|
;---------------------------------------------------------------------o

;=====================================================================o
;                           Esc Deletor                              ;|
;-----------------------------------o---------------------------------o
;                     Esc + n  |  Ctrl + Delete (Delete a Word)      ;|
;                     Esc + m  |  Delete                             ;|
;                     Esc + ,  |  BackSpace                          ;|
;                     Esc + .  |  Ctrl + BackSpace                   ;|
;-----------------------------------o---------------------------------o
Esc & ,:: Send, {Del}                                                ;|
Esc & .:: Send, ^{Del}                                               ;|
Esc & m:: Send, {BS}                                                 ;|
Esc & n:: Send, ^{BS}                                                ;|
;---------------------------------------------------------------------o

;=====================================================================o
;                           Esc Editor                               ;|
;-----------------------------------o---------------------------------o
;                     Esc + z  |  Ctrl + z (Cancel)                  ;|
;                     Esc + x  |  Ctrl + x (Cut)                     ;|
;                     Esc + c  |  Ctrl + c (Copy)                    ;|
;                     Esc + v  |  Ctrl + z (Paste)                   ;|
;                     Esc + a  |  Ctrl + a (Select All)              ;|
;                     Esc + y  |  Ctrl + z (Yeild)                   ;|
;                     Esc + w  |  Ctrl + Right(Move as [vim: w])     ;|
;                     Esc + b  |  Ctrl + Left (Move as [vim: b])     ;|
;-----------------------------------o---------------------------------o
Esc & z:: Send, ^z                                                   ;|
Esc & x:: Send, ^x                                                   ;|
Esc & c:: Send, ^{Insert}                                            ;|
Esc & v:: Send, +{Insert}                                            ;|
Esc & a:: Send, ^a                                                   ;|
Esc & y:: Send, ^y                                                   ;|
Esc & w:: Send, ^{Right}                                             ;|
Esc & b:: Send, ^{Left}                                              ;|
;---------------------------------------------------------------------o

;=====================================================================o
;                          Esc Media Controller                      ;|
;-----------------------------------o---------------------------------o
;                       Esc + F1  |  Media_Play_Pause                ;|
;                       Esc + F2  |  Media_Next                      ;|
;                       Esc + F3  |  Media_Prev                      ;|
;                       Esc + F4  |  Volume_Down                     ;|
;                       Esc + F5  |  Volume_Up                       ;|
;                       Esc + F6  |  Volume_Mute                     ;|
;-----------------------------------o---------------------------------o
Esc & F1:: Send, {Media_Play_Pause}                                  ;|
Esc & F2:: Send, {Media_Next}                                        ;|
Esc & F3:: Send, {Media_Prev}                                        ;|
Esc & F4:: Send, {Volume_Down}                                       ;|
Esc & F5:: Send, {Volume_Up}                                         ;|
Esc & F6:: Send, {Volume_Mute}                                       ;|
;---------------------------------------------------------------------o

;=====================================================================o
;                         Esc Window Controller                      ;|
;-----------------------------------o---------------------------------o
;                    Esc + s  |  Ctrl + Tab (Swith Tag)              ;|
;                    Esc + q  |  Alt + F4   (Close Windows)          ;|
;                    Esc + g  |  AppsKey    (Menu Key)               ;|
;-----------------------------------o---------------------------------o
Esc & s:: Send, ^{Tab}                                               ;|
;-----------------------------------o                                ;|
Esc & q:: Send, !{F4}                                                ;|
;-----------------------------------o                                ;|
Esc & d:: Send, {AppsKey}                                            ;|
;---------------------------------------------------------------------o

;=====================================================================o
;                        Esc Char Mapping                            ;|
;-----------------------------------o---------------------------------o
;                     Esc + ;  |  Enter                              ;|
;                     Esc + '  |  =                                  ;|
;-----------------------------------o---------------------------------o
Esc & `;:: Send, {Enter}                                             ;|
Esc & ':: Send, =                                                    ;|
;---------------------------------------------------------------------o

;=====================================================================o
;                      Esc Enhancement                                |
;---------------------------------------------------------------------o
;Description:                                                         |
;    This Script turns Esc into an function Key just like Ctrl and    |
; Alt by combining Esc with almost all other keys in the keyboard.    |
;                                                                     |
; See also:                                                           |
;    github.com/Vonng/Configuration/blob/master/win_ahk/CapsLock.ahk  |
;                                                                     |
;Summary:                                                             |
;o----------------------o---------------------------------------------o
;|Esc + `             | {CapsLock}CapsLock Switcher as a Substituent  |
;|Esc + {BackSpace}   | Exit                                          |
;|Esc + hjklwb        | Vim-Style Cursor Mover                        |
;|Esc + ioup          | Convient Home/End PageUp/PageDn               |
;|Esc + nm,.          | Convient Delete Controller                    |
;|Esc + zxcvay        | Windows-Style Editor                          |
;|Esc + Direction     | Mouse Move                                    |
;|Esc + Enter         | Mouse Click                                   |
;|Esc + {F1}~{F6}     | Media Controller                              |
;|Esc + qsd           | Windows & Tags Control                        |
;|Esc + ;'            | Convient Key Mapping                          |
;-----------------------o---------------------------------------------o
;|Use it whatever and wherever you like. Hope it help                 |
;=====================================================================o

;=====================================================================o
#NoTrayIcon                                                          ;|
#SingleInstance force                                                ;|
$Esc:: Send, {ESC}                                                   ;|
$^+Esc:: Send, ^+{Esc}                                               ;|
$#Esc:: ExitApp                                                      ;|
;=====================================================================o

;=====================================================================o
;                       CapsLock Switcher:                           ;|
;---------------------------------o-----------------------------------o
;                      Esc + ` | {CapsLock}                          ;|
;---------------------------------o-----------------------------------o
Esc & `::                                                            ;|
GetKeyState, CapsLockState, CapsLock, T                              ;|
if CapsLockState = D                                                 ;|
    SetCapsLockState, AlwaysOff                                      ;|
else                                                                 ;|
    SetCapsLockState, AlwaysOn                                       ;|
KeyWait, ``                                                          ;|
return                                                               ;|
;---------------------------------------------------------------------o

;=====================================================================o
;                     Esc Direction Navigator                        ;|
;-----------------------------------o---------------------------------o
;                        Esc + h |  Left                             ;|
;                        Esc + j |  Down                             ;|
;                        Esc + k |  Up                               ;|
;                        Esc + l |  Right                            ;|
;-----------------------------------o---------------------------------o
Esc & h::Send, {Left}                                                ;|
Esc & j::Send, {Down}                                                ;|
Esc & k::Send, {Up}                                                  ;|
Esc & l::Send, {Right}                                               ;|
;---------------------------------------------------------------------o

;=====================================================================o
;                       Esc Home/End Navigator                       ;|
;-----------------------------------o---------------------------------o
;                         Esc + i |  Home                            ;|
;                         Esc + o |  End                             ;|
;                      Ctrl, Alt Compatible                          ;|
;-----------------------------------o---------------------------------o
Esc & i::                                                            ;|
if GetKeyState("control") = 0                                        ;|
{                                                                    ;|
    if GetKeyState("alt") = 0                                        ;|
        Send, {Home}                                                 ;|
    else                                                             ;|
        Send, +{Home}                                                ;|
    return                                                           ;|
}                                                                    ;|
else {                                                               ;|
    if GetKeyState("alt") = 0                                        ;|
        Send, ^{Home}                                                ;|
    else                                                             ;|
        Send, +^{Home}                                               ;|
    return                                                           ;|
}                                                                    ;|
return                                                               ;|
;-----------------------------------o                                ;|
Esc & o::                                                            ;|
if GetKeyState("control") = 0                                        ;|
{                                                                    ;|
    if GetKeyState("alt") = 0                                        ;|
        Send, {End}                                                  ;|
    else                                                             ;|
        Send, +{End}                                                 ;|
    return                                                           ;|
}                                                                    ;|
else {                                                               ;|
    if GetKeyState("alt") = 0                                        ;|
        Send, ^{End}                                                 ;|
    else                                                             ;|
        Send, +^{End}                                                ;|
    return                                                           ;|
}                                                                    ;|
return                                                               ;|
;---------------------------------------------------------------------o

;=====================================================================o
;                        Esc Page Navigator                          ;|
;-----------------------------------o---------------------------------o
;                        Esc + u |  PageUp                           ;|
;                        Esc + p |  PageDown                         ;|
;                        Ctrl, Alt Compatible                        ;|
;-----------------------------------o---------------------------------o
Esc & u::                                                            ;|
if GetKeyState("control") = 0                                        ;|
{                                                                    ;|
    if GetKeyState("alt") = 0                                        ;|
        Send, {PgUp}                                                 ;|
    else                                                             ;|
        Send, +{PgUp}                                                ;|
    return                                                           ;|
}                                                                    ;|
else {                                                               ;|
    if GetKeyState("alt") = 0                                        ;|
        Send, ^{PgUp}                                                ;|
    else                                                             ;|
        Send, +^{PgUp}                                               ;|
    return                                                           ;|
}                                                                    ;|
return                                                               ;|
;-----------------------------------o                                ;|
Esc & p::                                                            ;|
if GetKeyState("control") = 0                                        ;|
{                                                                    ;|
    if GetKeyState("alt") = 0                                        ;|
        Send, {PgDn}                                                 ;|
    else                                                             ;|
        Send, +{PgDn}                                                ;|
    return                                                           ;|
}                                                                    ;|
else {                                                               ;|
    if GetKeyState("alt") = 0                                        ;|
        Send, ^{PgDn}                                                ;|
    else                                                             ;|
        Send, +^{PgDn}                                               ;|
    return                                                           ;|
}                                                                    ;|
return                                                               ;|
;---------------------------------------------------------------------o

;=====================================================================o
;                        Esc Mouse Controller                        ;|
;-----------------------------------o---------------------------------o
;                       Esc + Up   |  Mouse Up                       ;|
;                       Esc + Down |  Mouse Down                     ;|
;                       Esc + Left |  Mouse Left                     ;|
;                      Esc + Right |  Mouse Right                    ;|
;        Esc + Enter(Push Release) |  Mouse Left Push(Release)       ;|
;-----------------------------------o---------------------------------o
Esc & Up::    MouseMove, 0, -10, 0, R                                ;|
Esc & Down::  MouseMove, 0, 10, 0, R                                 ;|
Esc & Left::  MouseMove, -10, 0, 0, R                                ;|
Esc & Right:: MouseMove, 10, 0, 0, R                                 ;|
;-----------------------------------o                                ;|
Esc & Enter::                                                        ;|
SendEvent {Blind}{LButton down}                                      ;|
KeyWait Enter                                                        ;|
SendEvent {Blind}{LButton up}                                        ;|
return                                                               ;|
;---------------------------------------------------------------------o

;=====================================================================o
;                           Esc Deletor                              ;|
;-----------------------------------o---------------------------------o
;                     Esc + n  |  Ctrl + Delete (Delete a Word)      ;|
;                     Esc + m  |  Delete                             ;|
;                     Esc + ,  |  BackSpace                          ;|
;                     Esc + .  |  Ctrl + BackSpace                   ;|
;-----------------------------------o---------------------------------o
Esc & ,:: Send, {Del}                                                ;|
Esc & .:: Send, ^{Del}                                               ;|
Esc & m:: Send, {BS}                                                 ;|
Esc & n:: Send, ^{BS}                                                ;|
;---------------------------------------------------------------------o

;=====================================================================o
;                           Esc Editor                               ;|
;-----------------------------------o---------------------------------o
;                     Esc + z  |  Ctrl + z (Cancel)                  ;|
;                     Esc + x  |  Ctrl + x (Cut)                     ;|
;                     Esc + c  |  Ctrl + c (Copy)                    ;|
;                     Esc + v  |  Ctrl + z (Paste)                   ;|
;                     Esc + a  |  Ctrl + a (Select All)              ;|
;                     Esc + y  |  Ctrl + z (Yeild)                   ;|
;                     Esc + w  |  Ctrl + Right(Move as [vim: w])     ;|
;                     Esc + b  |  Ctrl + Left (Move as [vim: b])     ;|
;-----------------------------------o---------------------------------o
Esc & z:: Send, ^z                                                   ;|
Esc & x:: Send, ^x                                                   ;|
Esc & c:: Send, ^{Insert}                                            ;|
Esc & v:: Send, +{Insert}                                            ;|
Esc & a:: Send, ^a                                                   ;|
Esc & y:: Send, ^y                                                   ;|
Esc & w:: Send, ^{Right}                                             ;|
Esc & b:: Send, ^{Left}                                              ;|
;---------------------------------------------------------------------o

;=====================================================================o
;                          Esc Media Controller                      ;|
;-----------------------------------o---------------------------------o
;                       Esc + F1  |  Media_Play_Pause                ;|
;                       Esc + F2  |  Media_Next                      ;|
;                       Esc + F3  |  Media_Prev                      ;|
;                       Esc + F4  |  Volume_Down                     ;|
;                       Esc + F5  |  Volume_Up                       ;|
;                       Esc + F6  |  Volume_Mute                     ;|
;-----------------------------------o---------------------------------o
Esc & F1:: Send, {Media_Play_Pause}                                  ;|
Esc & F2:: Send, {Media_Next}                                        ;|
Esc & F3:: Send, {Media_Prev}                                        ;|
Esc & F4:: Send, {Volume_Down}                                       ;|
Esc & F5:: Send, {Volume_Up}                                         ;|
Esc & F6:: Send, {Volume_Mute}                                       ;|
;---------------------------------------------------------------------o

;=====================================================================o
;                         Esc Window Controller                      ;|
;-----------------------------------o---------------------------------o
;                    Esc + s  |  Ctrl + Tab (Swith Tag)              ;|
;                    Esc + q  |  Alt + F4   (Close Windows)          ;|
;                    Esc + g  |  AppsKey    (Menu Key)               ;|
;-----------------------------------o---------------------------------o
Esc & s:: Send, ^{Tab}                                               ;|
;-----------------------------------o                                ;|
Esc & q:: Send, !{F4}                                                ;|
;-----------------------------------o                                ;|
Esc & d:: Send, {AppsKey}                                            ;|
;---------------------------------------------------------------------o

;=====================================================================o
;                        Esc Char Mapping                            ;|
;-----------------------------------o---------------------------------o
;                     Esc + ;  |  Enter                              ;|
;                     Esc + '  |  =                                  ;|
;-----------------------------------o---------------------------------o
Esc & `;:: Send, {Enter}                                             ;|
Esc & ':: Send, =                                                    ;|
;---------------------------------------------------------------------o


[chore] Add comment

[chore] Add comment

; Autohotkey configuration file
; AHK Version v.1.1.32.00
; Franklin Chou (franklin.chou@nelsonmullins.com)
; 14 Apr. 2020
; Tested to work on Lenovo X1 Yoga, Gen. 4

#SingleInstance Force
#Persistent

GLOBAL_DEBUG_MODE := 0
Return

CapsLock::Ctrl
LCtrl::Return
; LCtrl::CapsLock

; DEBUG TOOLS -----------------------------------------------------------------

#c::
  If(GLOBAL_DEBUG_MODE > 0) {
    ; WinGetClass, title, A
    WinGetActiveTitle, title
    MsgBox %title%
  }
Return

f12::
  If(GLOBAL_DEBUG_MODE > 0) {
    Reload
  }
Return

; SYSTEM ----------------------------------------------------------------------

; Access different windows of the same group
!`::
  WinGet, process_name, ProcessName, A ; get the active window's process name
  process_windows := GetWindowsOfProcess(process_name)

  n_process_windows := process_windows.Length()

  index := 1 ; AHK arrays are 1 indexed
  While(GetKeyState("Alt", "P")) {
    If (GetKeyState("``", "P")) {
      If (index < n_process_windows) {
        index := index + 1
      } Else {
        index := 1
      }
      active_id := process_windows[index]
      WinActivate, ahk_id %active_id%
    }
  }

  index := ""
  process_windows := ""
  n_process_windows := ""
Return

; Get the window ids of all the processes under that process name
GetWindowsOfProcess(process_name) {
  ids := Array()
  WinGet, window_ids, List ; get the IDs for all running windows
  Loop %window_ids% {
    id := window_ids%A_Index%
    WinGetTitle, title, ahk_id %id%
    WinGet, a_process_name, ProcessName, ahk_id %id%
    ; only include windows with visible title
    If (title && a_process_name = process_name) {
      ids.Push(id)
    }
  }
  Return, ids
}

; utility to get selected text (if any)
GetSelectedText() {
  temp := ClipboardAll
  Send ^c
  ClipWait, 0, 1
  selection := Clipboard
  Clipboard := temp
  Return, selection
}

; TIMEKEEPER ------------------------------------------------------------------

; Shift focus to the timekeeper app
#!e::
  timekeeper_app := WinExist("ahk_class WindowsForms10.Window.8.app.0.262fb3d")
  If(timekeeper_app > 0) {
    WinActivate, ahk_id %timekeeper_app%
  } Else {
    Run, DTE.exe, C:\Program Files (x86)\DTEAxiom
  }
Return

; Start the timer on the selected item in the daily view
#IfWinActive ahk_class WindowsForms10.Window.8.app.0.262fb3d
  >+s::
    WinGetActiveTitle, active_title
    selected := GetSelectedText()
    is_releasable := RegExMatch(selected, "Ready to be released")
    ; match monthly view; 2 application windows
    If(is_releaseable && RegExMatch(active_title, "^Entries for") > 0) {
      WinMove, 0, 0
      ; when figuring out how low to get the mouse to move aim for the area
      ; of the menu ar that says "Drag a column header here..."
      MouseMove, 100, 280
      DTEAppContextClick(4)
    ; match weekly view, 1 application window
    } Else If (is_releasable && RegExMatch(active_title, "DTE Axiom") > 0) {
      WinMove, 0, 0
      MouseMove, 100, 440
      DTEAppContextClick(4)
    } Else {
      MsgBox Select releasable entry
      Return
    }
    is_releasable := ""
    selected := ""
Return

; click the item in the DTE context menu that is `position` from the top
DTEAppContextClick(position) {
    ; each item in the dropdown is approximately 25 pixels
    drop_down := 25
    Send {RButton}
    Sleep, 10 ; sleep to allow submenu time to come up
    MouseMove, 170, 300 + drop_down * position
    Send {LButton}
}

; MSOFFICE --------------------------------------------------------------------

; Let the print screen key open the application options key (for spell check)
; Word and Outlook
#If WinActive("ahk_class OpusApp") || WinActive("ahk_class rctrl_renwnd32")
  PrintScreen::AppsKey
Return

; This ridiculous keymapping is care of Lenovo
; which maps F12 to some bloatware keyboard manager utility
#If WinActive("ahk_class OpusApp") || WinActive("ahk_class XLMAIN")
  F12::
    Send {F12}
Return

; WORD ONLY -------------------------------------------------------------------

; Cycle through types of markup
#If WinActive("ahk_class OpusApp")
  >+m::
    Send !r
    Sleep, 10
    Send td
    Send {Down}
    Send {Enter}
Return

; Bring up the tab stop modification dialogue
#If WinActive("ahk_class OpusApp")
  >+t::
    Send !h
    Send pg
    Send !t
Return

; Autohotkey configuration file
; AHK Version v.1.1.32.00
; Franklin Chou (franklin.chou@nelsonmullins.com)
; 14 Apr. 2020
; Tested to work on Lenovo X1 Yoga, Gen. 4

#SingleInstance Force
#Persistent

GLOBAL_DEBUG_MODE := 0
Return

CapsLock::Ctrl
LCtrl::Return
; LCtrl::CapsLock

; DEBUG TOOLS -----------------------------------------------------------------

#c::
  If(GLOBAL_DEBUG_MODE > 0) {
    ; WinGetClass, title, A
    WinGetActiveTitle, title
    MsgBox %title%
  }
Return

f12::
  If(GLOBAL_DEBUG_MODE > 0) {
    Reload
  }
Return

; SYSTEM ----------------------------------------------------------------------

; Access different windows of the same group
!`::
  WinGet, process_name, ProcessName, A ; get the active window's process name
  process_windows := GetWindowsOfProcess(process_name)

  n_process_windows := process_windows.Length()

  index := 1 ; AHK arrays are 1 indexed
  While(GetKeyState("Alt", "P")) {
    If (GetKeyState("``", "P")) {
      If (index < n_process_windows) {
        index := index + 1
      } Else {
        index := 1
      }
      active_id := process_windows[index]
      WinActivate, ahk_id %active_id%
    }
  }

  index := ""
  process_windows := ""
  n_process_windows := ""
Return

; Get the window ids of all the processes under that process name
GetWindowsOfProcess(process_name) {
  ids := Array()
  WinGet, window_ids, List ; get the IDs for all running windows
  Loop %window_ids% {
    id := window_ids%A_Index%
    WinGetTitle, title, ahk_id %id%
    WinGet, a_process_name, ProcessName, ahk_id %id%
    ; only include windows with visible title
    If (title && a_process_name = process_name) {
      ids.Push(id)
    }
  }
  Return, ids
}

; utility to get selected text (if any)
GetSelectedText() {
  temp := ClipboardAll
  Send ^c
  ClipWait, 0, 1
  selection := Clipboard
  Clipboard := temp
  Return, selection
}

; TIMEKEEPER ------------------------------------------------------------------

; Shift focus to the timekeeper app
#!e::
  timekeeper_app := WinExist("ahk_class WindowsForms10.Window.8.app.0.262fb3d")
  If(timekeeper_app > 0) {
    WinActivate, ahk_id %timekeeper_app%
  } Else {
    Run, DTE.exe, C:\Program Files (x86)\DTEAxiom
  }
Return

; Start the timer on the selected item in the daily view
#IfWinActive ahk_class WindowsForms10.Window.8.app.0.262fb3d
  >+s::
    WinGetActiveTitle, active_title

    selected := GetSelectedText()
    is_releasable := RegExMatch(selected, "Ready to be released")

    ; match monthly view; 2 application windows
    If(is_releaseable && RegExMatch(active_title, "^Entries for") > 0) {
      WinMove, 0, 0
      ; when figuring out how low to get the mouse to move aim for the area
      ; of the menu ar that says "Drag a column header here..."
      MouseMove, 100, 280
      DTEAppContextClick(4)
    } Else If (is_releasable && RegExMatch(active_title, "DTE Axiom") > 0) {
      WinMove, 0, 0
      MouseMove, 100, 440
      DTEAppContextClick(4)
    } Else {
      MsgBox Select releasable entry
      Return
    }
    is_releasable := ""
    selected := ""
Return

; click the item in the DTE context menu that is `position` from the top
DTEAppContextClick(position) {
    ; each item in the dropdown is approximately 25 pixels
    drop_down := 25
    Send {RButton}
    Sleep, 10 ; sleep to allow submenu time to come up
    MouseMove, 170, 300 + drop_down * position
    Send {LButton}
}

; MSOFFICE --------------------------------------------------------------------

; Let the print screen key open the application options key (for spell check)
; Word and Outlook
#If WinActive("ahk_class OpusApp") || WinActive("ahk_class rctrl_renwnd32")
  PrintScreen::AppsKey
Return

; This ridiculous keymapping is care of Lenovo
; which maps F12 to some bloatware keyboard manager utility
#If WinActive("ahk_class OpusApp") || WinActive("ahk_class XLMAIN")
  F12::
    Send {F12}
Return

; WORD ONLY -------------------------------------------------------------------

; Cycle through types of markup
#If WinActive("ahk_class OpusApp")
  >+m::
    Send !r
    Sleep, 10
    Send td
    Send {Down}
    Send {Enter}
Return

; Bring up the tab stop modification dialogue
#If WinActive("ahk_class OpusApp")
  >+t::
    Send !h
    Send pg
    Send !t
Return