Advertisement
lightningleaf

Cycling through alternate characters not on some keyboards

Jun 4th, 2016
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. {
  2.     global DoTimeout := false ; toggle
  3.    
  4.     global DefaultCursorBlinkRate := .530 ; in seconds (530ms). Windows 10 default
  5.     global TimeoutTime := 2.5 * DefaultCursorBlinkRate
  6.     global TimeoutString := DoTimeout ? "T" . TimeoutTime :
  7. }
  8.  
  9. ; Allows the user to choose a string in KeysArray. Switching between strings is toggled by pressing the CycleKey.
  10. ; Despite what the name implies, strings in KeysArray can contain more than one character.
  11. CycleAltKeys(KeysArray, CycleKey) {
  12.     SendInput % KeysArray[1]
  13.     Input LastKey, %TimeoutString% L1, {BS}
  14.     count := 0
  15.     while LastKey = CycleKey {
  16.         Backspaces(StrLenU(KeysArray[count + 1]))
  17.         ModIncrement(count, KeysArray.MaxIndex())
  18.         SendInput % KeysArray[count + 1]
  19.         Input, LastKey, %TimeoutString% L1, {BS}
  20.     }
  21.    
  22.     if ErrorLevel = EndKey:Backspace
  23.     {
  24.         SendInput {BS}
  25.     }
  26.     if ErrorLevel = Timeout
  27.     {
  28.         SendInput {Space}
  29.     }
  30.     else {
  31.         SendInput % LastKey
  32.     }
  33. }
  34.  
  35. ; Sends Num amount of backspaces.
  36. Backspaces(Num) {
  37.     Loop %Num% {
  38.         SendInput {BS}
  39.     }
  40. }
  41.  
  42. ; Performs modular incrementation on Num.
  43. ModIncrement(ByRef Num, Modulus) {
  44.     Num := Mod(Num + 1, Modulus)
  45. }
  46.  
  47. ; Determines the length of the string Str containg escaped Unicode characters.
  48. StrLenU(Str) {
  49.     return StrLen(RegExReplace(Str, "{U\+\w+}", "⨯"))
  50. }
  51.  
  52. ; Allows the user to choose between "equals" (=) and "approximately equals" (≈), using just the "equals" key provided on most keyboards.
  53. =::CycleAltKeys(["{U+003D}", "{U+2248}"], "``")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement