Advertisement
Guest User

Untitled

a guest
Jan 19th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.24 KB | None | 0 0
  1. ; To add a new key to the script, add it to this array:
  2. key_list := ["1", "2", "3", "4", "q", "e", "r", "t", "f", "v", "g", "z", "x", "c", "b"]
  3.  
  4. ; Init lookup array for modifiers
  5. modifiers := {LShift: 0, LCtrl: 0, LAlt: 0}
  6.  
  7. ; Build lookup array, declare hotkeys
  8. keys := {}
  9. keys_modded := {}
  10. Loop % key_list.MaxIndex(){
  11. key := key_list[A_Index]
  12. ; init array values
  13. keys[key] := 0
  14. keys_modded[key] := 0
  15. ; Declare hotkeys for up and down events
  16. hotkey, $*%key%, keydown
  17. hotkey, $*%key% up, keyup
  18. }
  19.  
  20. Loop {
  21. ; Endless loop - always running
  22. for key, value in keys {
  23. ; Loop through each of the keys
  24. if (value){
  25. ; If the key is held...
  26.  
  27. ; Detect if any modifiers held
  28. if (modifiers.LCtrl || modifiers.LShift){
  29. modifier_held := 1
  30. } else {
  31. modifier_held := 0
  32. }
  33.  
  34. if (key = "q" && modifiers.LCtrl){
  35. ; Special case - CTRL + Q
  36. if (keys_modded[key]){
  37. ; We already sent a modded version of this key, then ignore
  38. ; keys_modded[key] will be set to 0 on up event of key
  39. continue
  40. } else {
  41. ; We are going to send a modded version of this key, set keys_modded[key] to 1, so it ignores next time
  42. keys_modded[key] := 1
  43. }
  44. }
  45.  
  46. if (key = "g" && modifier_held){
  47. ; Special case - ANY modifier and g
  48. if (keys_modded[key]){
  49. continue
  50. } else {
  51. keys_modded[key] := 1
  52. }
  53. }
  54.  
  55. ; Build the list of modifiers to use for the send
  56. s := ""
  57. if (modifiers.LShift){
  58. s .= "+"
  59. }
  60. if (modifiers.LCtrl){
  61. s .= "^"
  62. }
  63.  
  64. ; Send the key with the modifiers
  65. Send % s "{" key "}"
  66. }
  67. }
  68. Sleep 20
  69. }
  70.  
  71. ; Any of the "keys" (ie not modifiers) being pressed will call this
  72. keydown:
  73. key := SubStr(A_ThisHotkey,3)
  74. keys[key] := 1
  75. return
  76.  
  77. ; Any of the "keys" being released will call this
  78. keyup:
  79. key := SubStr(A_ThisHotkey,3)
  80. ; Remove " up" from end
  81. key := substr(key, 1, StrLen(key) - 3)
  82. keys[key] := 0
  83. keys_modded[key] := 0
  84. return
  85.  
  86. ; Modifiers
  87. $*LShift::
  88. $*LCtrl::
  89. mod := substr(A_ThisHotkey, 3)
  90. modifiers[mod] := 1
  91. return
  92.  
  93. $*LCtrl up::
  94. $*LShift up::
  95. mod := substr(A_ThisHotkey, 3)
  96. ; Remove " up" from end
  97. mod := substr(mod, 1, StrLen(mod) - 3)
  98. modifiers[mod] := 0
  99. return
  100. Enter::
  101. ExitApp
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement