Advertisement
lightningleaf

CycleAltKeys (v2a)

Jan 1st, 2017
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #SingleInstance Force
  2. #InstallKeybdHook
  3. SendMode Input
  4. global altKeys := {"foo" : "bar"
  5.     ,   "a":{"``":["α"]}
  6.     , "b":{"``":["β"]}
  7.     , "d":{"``":["Δ"]}
  8.     , "e":{"``":["ε", "∈"]}
  9.     , "i":{"``":["ᵢ"]}
  10.     , "k":{"``":["κ"]}
  11.     , "l":{"``":["λ"]}
  12.     , "o":{"``":["θ", "φ", "°"]}
  13.     , "p":{"``":["ρ"]}
  14.     , "r":{"``":["Γ", "ℝ"]}
  15.     , "s":{"``":["σ", "Σ"]}
  16.     , "t":{"``":["τ"]}
  17.     , "u":{"``":["μ"]}
  18.     , "w":{"``":["ω"]}
  19.     , "x":{"``":["χ"]}
  20.     , "y":{"``":["γ"]}
  21.     , "z":{"``":["ℤ"]}
  22.     , "=":{"``":["≈", "≠", "≡"]}
  23.     , "<":{"``":["≤"]}
  24.     , ">":{"``":["≥"]}
  25.     , "~":{"``":["∝"]}
  26.     , "+":{"``":["±", "⊕"]}
  27.     , "-":{"``":["∓"]}
  28.     , "*":{"``":["⋅", "⨯"]}
  29.     , "/":{"``":["√", "∛"]}
  30.     , "0":{"``":["∅"]}
  31.     , "1":{"``":["¹"]}
  32.     , "2":{"``":["²"]}
  33.     , "3":{"``":["³"]}
  34.     , "4":{"``":["⁴"]}
  35.     , "8":{"``":["∞"]}
  36.     , "_":{"``":["⌊⌋"]}
  37.     , "'":{"``":["′", "″", "‴"]}
  38.     , ".":{"``":["…"]} }
  39.  
  40. global InvisibleKeys := "{LControl}{RControl}{LAlt}{RAlt}{LShift}{RShift}{LWin}{RWin}{AppsKey}{F1}{F2}{F3}{F4}{F5}{F6}{F7}{F8}{F9}{F10}{F11}{F12}{Left}{Right}{Up}{Down}{Home}{End}{PgUp}{PgDn}{Del}{Ins}{BS}{CapsLock}{NumLock}{PrintScreen}"
  41.  
  42. ;TODO : define a function to loop through all cycle keys in altKeys.
  43. cak := Func("CycleAltKeys")
  44. Hotkey ``, %cak% ; how the hell do I inline this?
  45.  
  46. CycleAltKeys() {   
  47.     Hotkey %A_ThisHotkey%, Off
  48.     if (altKeys.HasKey(A_PriorKey) and altKeys[A_PriorKey].HasKey(A_ThisHotkey)) {
  49.         Keys := altKeys[A_PriorKey][A_ThisHotkey].Clone()
  50.     }
  51.     else {
  52.         Send % A_ThisHotkey
  53.         Hotkey %A_ThisHotkey%, On
  54.         return
  55.     }
  56.     Keys.InsertAt(1, A_PriorKey)
  57.     count := 0
  58.     LastKey := A_ThisHotkey
  59.     while (LastKey = A_ThisHotkey) {
  60.         Send % "{Backspace " . StrLen(Keys[count+1]) . "}"
  61.         ModIncrement(count, Keys.MaxIndex())
  62.         Send % Keys[count+1]
  63.         Input LastKey, L1, %InvisibleKeys%
  64.     }
  65.  
  66.     { ; Sends the last key press when it isn't for cycling.
  67.         ExitKey := InStr(ErrorLevel, ":") ? StrSplit(ErrorLevel, ":")[2] : ErrorLevel
  68.  
  69.                if ExitKey = "LControl"
  70.         {   Send {LControl Down}
  71.         } else if ExitKey = "RControl"
  72.         {   Send {RControl Down}
  73.         } else if ExitKey = "LAlt"
  74.         {   Send {LAlt Down}
  75.         } else if ExitKey = "RAlt"
  76.         {   Send {RAlt Down}
  77.         } else if ExitKey = "LShift"
  78.         {   Send {LShift Down}
  79.         } else if ExitKey = "RShift"
  80.         {   Send {RShift Down} 
  81.         } else if ExitKey = "Timeout"
  82.         {   throw Exception("Shouldn't go here: " . %ErrorLevel%)
  83.         } else if ExitKey = "Max"
  84.         {   Send % LastKey
  85.         } else if ExitKey = "Match"
  86.         {   throw Exception("Shouldn't go here: " . %ErrorLevel%)
  87.         } else
  88.         {   Send {Backspace}
  89.         }
  90.     }
  91.     Hotkey %A_ThisHotkey%, On
  92. }
  93.  
  94. ModIncrement(ByRef Num, Modulus) { ; Performs modular incrementation on Num.
  95.     Num := Mod(Num + 1, Modulus)
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement