Advertisement
Guest User

G19 Colors Cycling Script

a guest
Dec 15th, 2014
402
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.83 KB | None | 0 0
  1. -- G19 Backlight Colour-Cycling Script
  2. -- ------------------------------------------
  3. -- Cobbled together and imaginatively titled by
  4. -- White--Hawk (GH) - Edited in german by Jackjan
  5.  
  6. -- Thanks to everyone.
  7.  
  8.  
  9. ---------------
  10. ----------|| CONTROLS: ||--------------
  11. -- --------------- --
  12. -- --
  13. -- --
  14. -- R-Ctrl + --
  15. -- M1 - Cycle R<>G --
  16. -- M2 - Cycle G<>B --
  17. -- M3 - Cycle B<>R --
  18. -- --
  19. -- R-Shift + --
  20. -- M1 - Cycle RGB --
  21. -- M2 - Cycle RBG --
  22. -- M3 - Colour Picker --
  23. -- --
  24. -- While Cycling: --
  25. -- R-Shift + --
  26. -- L-Shift - Faster --
  27. -- L-Ctrl - Slower --
  28. -- --
  29. -- L-Shift + --
  30. -- R-Ctrl - Toggle LHC mode --
  31. -- (G19/G13 sync) --
  32. -- --
  33. -- While Picking: --
  34. -- R-Shift/R-Ctrl (brighter/darker) + --
  35. -- L-Shift - Red --
  36. -- L-Ctrl - Green --
  37. -- L-Alt - Blue --
  38. -- --
  39. -- Press any other MKey to stop --
  40. -- cycling or picking, and keep --
  41. -- selected colour. --
  42. -- --
  43. -- --
  44. -----------------------------------------
  45.  
  46. -- **Cycle rate:
  47. -- **(default = 150; red-to-red in ~23secs)
  48. -- **(always set lower than mrate)
  49. rate = 150
  50.  
  51. -- **Minimum delay:
  52. -- **(default = 600; red-to-red in ~1.5mins)
  53. -- **(higher is slower)
  54. mrate = 600
  55.  
  56. -- **Static (RGB) Colour:
  57. -- **(default = 140, 255, 150; white on my G19)
  58. R, G, B = 140, 255, 150
  59.  
  60. function OnEvent(event,arg)
  61.  
  62. -- Cycle or set custom colour:
  63. if (event=="M_PRESSED") and IsModifierPressed("rshift") then
  64.  
  65. -- Cycle RGB:
  66. if arg==1 then Cycle(0, 5, 0, 1, arg)
  67.  
  68. -- Cycle RBG:
  69. elseif arg==2 then Cycle(255, -5, 2, -1, arg)
  70.  
  71. else
  72.  
  73. -- Set custom static colour. Right Shift/Ctrl(+/-) plus Left-Shift/Ctrl/Alt(R/G/B).
  74. run=1
  75. while run~=null do
  76. if IsModifierPressed("rshift") then
  77. if IsModifierPressed("lshift") then R=R+.1
  78. if R>255 then R=255; end
  79. end
  80. if IsModifierPressed("lctrl") then G=G+.1
  81. if G>255 then G=255; end
  82. end
  83. if IsModifierPressed("lalt") then B=B+.1
  84. if B>255 then B=255; end
  85. end
  86. elseif IsModifierPressed("rctrl") then
  87. if IsModifierPressed("lshift") then R=R-.1
  88. if R<0 then R=0; end
  89. end
  90. if IsModifierPressed("lctrl") then G=G-.1
  91. if G<0 then G=0; end
  92. end
  93. if IsModifierPressed("lalt") then B=B-.1
  94. if B<0 then B=0; end
  95. end
  96. end
  97. SetBacklightColor(math.floor(R),math.floor(G),math.floor(B))
  98. if (IsModifierPressed("lalt") and IsModifierPressed("ralt")) or GetMKeyState()~=3 then run=null; break; end
  99. end
  100.  
  101. -- All done? Re-set new static colour after profiler applies default one.
  102. Sleep(350)
  103. SetBacklightColor(math.floor(R),math.floor(G),math.floor(B))
  104. end
  105.  
  106. end
  107.  
  108. -- Reciprocating fade; Red <> Green or Green <> Blue or Blue <> Red:
  109. if (event=="M_PRESSED") and IsModifierPressed("rctrl") then Fade(arg); end
  110.  
  111. end
  112.  
  113. function Fade(ks)
  114. fs=0; fj=5; fd=0; run=1
  115. while run~=null do
  116.  
  117. -- Ramp colour value 0-255 (and back), or full-off to full-on.
  118. for col = fs, 255-fs, fj do
  119.  
  120. -- Call for delay before next colour change.
  121. Dlay(ks)
  122.  
  123. if ks==1 then SetBacklightColor(255-col,col,0,"kb"); if lmode~="1" then SetBacklightColor(255-col,col,0,"lhc") else SetBacklightColor(col,255-col,0,"lhc") end
  124. elseif ks==2 then SetBacklightColor(0,255-col,col,"kb"); if lmode~="1" then SetBacklightColor(0,255-col,col,"lhc") else SetBacklightColor(0,col,255-col,"lhc") end
  125. elseif ks==3 then SetBacklightColor(col,0,255-col,"kb"); if lmode~="1" then SetBacklightColor(col,0,255-col,"lhc") else SetBacklightColor(255-col,0,col,"lhc") end
  126. end
  127.  
  128. -- Skip out of ramps...
  129. if run==null then break; end
  130.  
  131. end
  132.  
  133. -- Change direction...
  134. if fd==0 then fd=1; fs=255; fj=-5
  135. else fd=0; fs=0; fj=5
  136.  
  137. -- Skip out of reciprocating fade...
  138. if run==null then break; end
  139. end
  140. end
  141. end
  142.  
  143. function Cycle(cs, cj, rs, rj, ks)
  144. run=1
  145. while run~=null do
  146.  
  147. -- Loop through each of R, G, and B.
  148. for rgb = rs, 2-rs, rj do
  149.  
  150. -- Ramp colour value 0-255, or full-off to full-on.
  151. for col = cs, 255-cs, cj do
  152.  
  153. -- Call for delay before next colour change.
  154. Dlay(ks)
  155.  
  156. if rgb==0 then SetBacklightColor(255-col,col,0,"kb"); if lmode~="1" then SetBacklightColor(255-col,col,0,"lhc") else SetBacklightColor(col,0,255-col,"lhc") end
  157. elseif rgb==1 then SetBacklightColor(0,255-col,col,"kb"); if lmode~="1" then SetBacklightColor(0,255-col,col,"lhc") else SetBacklightColor(255-col,col,0,"lhc") end
  158. elseif rgb==2 then SetBacklightColor(col,0,255-col,"kb"); if lmode~="1" then SetBacklightColor(col,0,255-col,"lhc") else SetBacklightColor(0,255-col,col,"lhc") end
  159. end
  160.  
  161. if run==null then break; end
  162. end
  163.  
  164. -- Skip out of RGB loops...
  165. if run==null then break; end
  166. end
  167.  
  168. end
  169. end
  170.  
  171. function Dlay(ks)
  172. -- Throttle controls during sleep.
  173. for z = 1, rate, 1 do
  174.  
  175. -- Faster...
  176. if IsModifierPressed("lshift") and IsModifierPressed("rshift") then rate=(rate-(mrate/6000))
  177. if rate<2 then rate=2
  178. if limit~=0 then limit=0; OutputLCDMessage("\n"..(string.rep(" ",37)).."Maximum", 3000); end
  179. end
  180. -- Increments for display...
  181. dup=math.floor((60/mrate)*rate)
  182. if nup~=dup then Disp(); end
  183.  
  184. -- Slower...
  185. elseif IsModifierPressed("lctrl") and IsModifierPressed("rshift") then rate=(rate+(mrate/6000))
  186. if rate>mrate then rate=mrate; end
  187. -- Increments for display...
  188. dup=math.floor((60/mrate)*rate)
  189. if nup~=dup or limit~=1 then Disp(); limit=1; end
  190. end
  191.  
  192. -- ~333ms control delay...
  193. if tt==null then tt=0 elseif tt<334 then tt=tt+1 end
  194. if tt>333 and IsModifierPressed("rctrl") and IsModifierPressed("lshift") then tt=0
  195. if lmode~="1" then lmode="1" else lmode="0" end
  196. end
  197.  
  198. -- Don't wait for delay if another M-key is pressed.
  199. if GetMKeyState()~=ks or (IsModifierPressed("lalt") and IsModifierPressed("ralt")) then run=null; break; end
  200. Sleep(1)
  201.  
  202. end
  203. end
  204.  
  205. function Disp()
  206. -- Draw an incremental slider to G19 LCD output. It grabs/drops focus rapidly. :S
  207. text="\n\n\n\n\n\n <["..(string.rep("||",60-dup)).."|||"..(string.rep("-",dup)).."]>"
  208. ClearLCD(); OutputLCDMessage(text, 2000)
  209. nup=dup
  210. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement