zero3growlithe

GPD WIN 2 AutoHotKey shortcuts

Apr 23rd, 2019
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ; LAST UPDATED 11-May-2019
  2. ; Changelog
  3. ; 11-05-2019
  4. ; - hold keys no longer repeat input upon alternate key activation
  5. #NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
  6. ; #Warn  ; Enable warnings to assist with detecting common errors.
  7. SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
  8. SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
  9. #SingleInstance
  10. #Persistent
  11. #KeyHistory 0
  12.  
  13. ; ===============================================
  14. ; >>>>>>>>>>>>> SETTINGS <<<<<<<<<<<<<
  15. ; change these to your liking
  16. ; ===============================================
  17.  
  18. global AlternateFunctionActivationDelay := 250 ; time in miliseconds (1000 = 1 second)
  19.  
  20. ; ===============================================
  21. ; >>>>>>>>>>>>> TIPS AND NOTES <<<<<<<<<<<<<
  22. ; ===============================================
  23.  
  24. ; $ sign before hotkey allows us to use the key bound to the hotkey in the function it invokes
  25. ; ~ sign does what $ sign does while also activating this key as if it was not a hotkey
  26. ;
  27. ; ^ sign is for CONTROL modifier key
  28. ; + sign is for SHIFT modifier key
  29. ; ! sign is for ALT modifier key
  30.  
  31. ; ===============================================
  32. ; >>>>>>>>>>>>> KEY MAPPINGS - HOTKEYS <<<<<<<<<<<<<
  33. ; change these to your liking
  34. ; ===============================================
  35.  
  36. ; add second row of function keys to F1 - F6
  37. $F1::TryToActivateAlternateKeyOnHold("F1", "", "{F7}", AlternateFunctionActivationDelay)
  38. $F2::TryToActivateAlternateKeyOnHold("F2", "", "{F8}", AlternateFunctionActivationDelay)
  39. $F3::TryToActivateAlternateKeyOnHold("F3", "", "{F9}", AlternateFunctionActivationDelay)
  40. $F4::TryToActivateAlternateKeyOnHold("F4", "", "{F10}", AlternateFunctionActivationDelay)
  41. $F5::TryToActivateAlternateKeyOnHold("F5", "", "{F11}", AlternateFunctionActivationDelay)
  42. $F6::TryToActivateAlternateKeyOnHold("F6", "", "{F12}", AlternateFunctionActivationDelay)
  43.  
  44. ; XButton1 corresponds to "back" key on some computer mice
  45. $-::TryToActivateAlternateKeyOnHold("-", "", "{XButton1}", AlternateFunctionActivationDelay)
  46.  
  47. ; XButton2 corresponds to "forward" key on some computer mice
  48. $=::TryToActivateAlternateKeyOnHold("=", "", "{XButton2}", AlternateFunctionActivationDelay)
  49.  
  50. ; maps L3 and R3 buttons (bumpers) as volume keys when GPD WIN is in mouse input mode
  51. ; useful as MP3 player shortcut when GPD WIN is closed
  52. ; warning: this locks these keys for normal usage
  53. ; -----------------
  54. Numpad1::Volume_Down
  55. Numpad2::Volume_Up
  56. ; Numpad1::Volume_Mute
  57. ; Numpad2::Media_Play_Pause
  58.  
  59. ; alternative ways to set volume
  60. ; Numpad1::SoundSet, -5
  61. ; Numpad2::SoundSet, +5
  62. ; Numpad1::SoundSet, 50
  63.  
  64. ; Using Alt-Tab shortcut on Polish keyboard is troublesome due to Right Alt being AltGr (which is Ctrl + Alt)
  65. ; This makes the Alt-Tab window not disappear automatically after you let got of the shortcut keys
  66. ; This line fixes that.
  67. RAlt & Tab::AltTab
  68.  
  69. ; ===============================================
  70. ; >>>>>>>>>>>>> VARIABLES <<<<<<<<<<<<<
  71. ; ===============================================
  72. global WasPassthroughActivated
  73. global LastHotkeyPressTime
  74. global CachedInputActivationKey := "F1"
  75. global CachedAlternateKeyToActivate
  76. global CachedActivationHoldDelayTime
  77. global IsAlternateInputLocked
  78.  
  79. ; ===============================================
  80. ; >>>>>>>>>>>>> FUNCTIONS <<<<<<<<<<<<<
  81. ; ===============================================
  82. LockInputTimer()
  83. {
  84.     if (GetKeyState(CachedInputActivationKey, "P") == false)
  85.     {
  86.         IsAlternateInputLocked := false
  87.         SetTimer, LockInputTimer, Off
  88.     }
  89. }
  90.  
  91. TryToActivateAlternateKeyOnHold(functionKeyName, modifiers, secondaryFunctionKey, holdTime, inputKeyPassthrough := false)
  92. {
  93.     if (IsAlternateInputLocked == true)
  94.     {
  95.         return
  96.     }
  97.  
  98.     IsAlternateInputLocked := false
  99.     LastHotkeyPressTime := A_TickCount
  100.  
  101.     ; if inputKeyPassthrough is on, activate the input key once on start
  102.     if (inputKeyPassthrough == true)
  103.     {
  104.         SendInput, %modifiers%{%functionKeyName%}
  105.     }
  106.  
  107.     ; pass input as normal if allowActivatorInput is on
  108.     WasPassthroughActivated := inputKeyPassthrough
  109.     CachedInputActivationKey := functionKeyName
  110.     CachedAlternateKeyToActivate := secondaryFunctionKey
  111.     CachedActivationHoldDelayTime := holdTime
  112.  
  113.     if (GetKeyState(CachedInputActivationKey, "P") == true)
  114.     {
  115.         SetTimer, ActivateAlternateKeysAfterDelayTimer, 1
  116.     }
  117. }
  118.  
  119. ActivateAlternateKeysAfterDelayTimer()
  120. {
  121.     ; cancel alternate input if activator key is not held anymore
  122.     while (A_TickCount - LastHotkeyPressTime < CachedActivationHoldDelayTime)
  123.     {
  124.         if (GetKeyState(CachedInputActivationKey, "P") == false && WasPassthroughActivated == false)
  125.         {
  126.             SendInput, {%CachedInputActivationKey%}
  127.             SetTimer, ActivateAlternateKeysAfterDelayTimer, Off
  128.  
  129.             return
  130.         }
  131.     }
  132.  
  133.     ; if the activator key is still pressed, we want the secondary key function
  134.     if (GetKeyState(CachedInputActivationKey, "P") == true)
  135.     {
  136.         SendInput, %CachedAlternateKeyToActivate%
  137.  
  138.         IsAlternateInputLocked := true
  139.         SetTimer, LockInputTimer, 5
  140.     }
  141.  
  142.     ; disable timer to prevent looping
  143.     SetTimer, ActivateAlternateKeysAfterDelayTimer, Off
  144.  
  145.     return
  146. }
  147.  
  148. ; ===============================================
  149. ; >>>>>>>>>>>>> OTHER - REGIONAL <<<<<<<<<<<<<
  150. ; ===============================================
  151. ; NON-ENGLISH LANGUAGES IMPROVEMENTS (POLISH IN THIS CASE)
  152. ; LOWERCASE - polish characters on-key-hold
  153. ; $e::TryToActivateAlternateKeyOnHold("e", "", "{Backspace 1}^!{e}", AlternateFunctionActivationDelay, true)
  154. ; $o::TryToActivateAlternateKeyOnHold("o", "", "{Backspace 1}^!{o}", AlternateFunctionActivationDelay, true)
  155. ; $a::TryToActivateAlternateKeyOnHold("a", "", "{Backspace 1}^!{a}", AlternateFunctionActivationDelay, true)
  156. ; $s::TryToActivateAlternateKeyOnHold("s", "", "{Backspace 1}^!{s}", AlternateFunctionActivationDelay, true)
  157. ; $l::TryToActivateAlternateKeyOnHold("l", "", "{Backspace 1}^!{l}", AlternateFunctionActivationDelay, true)
  158. ; $z::TryToActivateAlternateKeyOnHold("z", "", "{Backspace 1}^!{z}", AlternateFunctionActivationDelay, true)
  159. ; $x::TryToActivateAlternateKeyOnHold("x", "", "{Backspace 1}^!{x}", AlternateFunctionActivationDelay, true)
  160. ; $c::TryToActivateAlternateKeyOnHold("c", "", "{Backspace 1}^!{c}", AlternateFunctionActivationDelay, true)
  161. ; $n::TryToActivateAlternateKeyOnHold("n", "", "{Backspace 1}^!{n}", AlternateFunctionActivationDelay, true)
  162.  
  163. ; UPPERCASE - polish characters on-key-hold
  164. ; $+e::TryToActivateAlternateKeyOnHold("e", "+", "{Backspace 1}^!+{e}", AlternateFunctionActivationDelay, true)
  165. ; $+o::TryToActivateAlternateKeyOnHold("o", "+", "{Backspace 1}^!+{o}", AlternateFunctionActivationDelay, true)
  166. ; $+a::TryToActivateAlternateKeyOnHold("a", "+", "{Backspace 1}^!+{a}", AlternateFunctionActivationDelay, true)
  167. ; $+s::TryToActivateAlternateKeyOnHold("s", "+", "{Backspace 1}^!+{s}", AlternateFunctionActivationDelay, true)
  168. ; $+l::TryToActivateAlternateKeyOnHold("l", "+", "{Backspace 1}^!+{l}", AlternateFunctionActivationDelay, true)
  169. ; $+z::TryToActivateAlternateKeyOnHold("z", "+", "{Backspace 1}^!+{z}", AlternateFunctionActivationDelay, true)
  170. ; $+x::TryToActivateAlternateKeyOnHold("x", "+", "{Backspace 1}^!+{x}", AlternateFunctionActivationDelay, true)
  171. ; $+c::TryToActivateAlternateKeyOnHold("c", "+", "{Backspace 1}^!+{c}", AlternateFunctionActivationDelay, true)
  172. ; $+n::TryToActivateAlternateKeyOnHold("n", "+", "{Backspace 1}^!+{n}", AlternateFunctionActivationDelay, true)
Add Comment
Please, Sign In to add comment