Your Ad Here
Page 1 of 12 12311 ... LastLast
Results 1 to 10 of 120

Thread: G19 & G13 Backlight Colour Cycle Script

  1. #1
    White--Hawk is offline G15 Forums GOD
    Join Date
    Aug 2008
    Location
    At home.
    Posts
    1,440

    Talking G19 & G13 Backlight Colour Cycle Script

    UPDATE: 29/12/09 - Added feature for users of both a G19 and a G13 (colour un-sync)!
    UPDATE: 16/12/09 - Added bi-colour fades; R<>G, G<>B, or B<>R.
    UPDATE: 29/10/09 - Completely re-wrote sleep/control routine, tidied some more.
    UPDATE: 27/10/09 - Tweaked rate control/slider, removed redundant stuff.
    UPDATE: 25/10/09 - Even shorter script, edited script comments.
    UPDATE: 23/10/09 - Tidier, commented, and smoother speed indicator.


    |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
    Download the script >>>here<<<.
    Or simply copy all the text from the code box below into the script editor.
    |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||

    This script allows you to loop through R>G>B (forwards or
    backwards) or just between two colours (R&G, G&B, B&R)
    at a user-selectable speed, or to manually set a custom
    colour without accessing the profiler.

    At the very least, it gives a nice demo of the backlight
    and opens up a range of custom colours with just a few
    key presses.

    When changing rate, an indicator is displayed on the LCD.

    To install the script, open the Logitech Keyboard
    Profiler, select the correct profile from the drop-down menu
    (eg- 'Default Configuration' to operate the backlight on
    the desktop, or your favorite game, or both), and go to
    the menu, Edit > Script Editor.

    Either use File > Import OR replace the text in the editor
    with the script in the code box below. Go to File > Save.

    |||||||||||||||||||||||||||||||||||||||||||||||||

    Controls:
    R-Ctrl +
    -M1------------------------Cycle R<>G
    -M2------------------------Cycle G<>B
    -M3------------------------Cycle B<>R
    R-Shift +
    -M1------------------------Cycle RGB
    -M2------------------------Cycle RBG
    -M3------------------------Colour Picker
    While cycling:
    R-Shift +
    -L-Shift--------------------Faster
    -L-Ctrl---------------------Slower
    R-Ctrl +
    -L-Shift--------------------Unsync G19 and G13
    While Picking:
    R-Shift/R-Ctrl (brighter/darker) +
    -L-Shift--------------------Red
    -L-Ctrl---------------------Green
    -L-Alt----------------------Blue
    Any other M-key----------Keep new colour!
    *
    L-Alt + R-Alt--------------Keep new colour!
    *


    *last selected or cycled colour is retained until a further M-key press,
    so lots of new colours are accessible without opening the profiler, either
    by manually mixing a custom colour, or by halting the colour cycler
    when the desired colour appears. The colour will be retained until a
    change of M mode.

    The dual Alt press should abort the script even if the profiler freezes.


    |||||||||||||||||||||||||||||||||||||||||||||||||

    Code:
    --  G19 Backlight Colour-Cycling Script (v3.1)
    --  ------------------------------------------
    --  Cobbled together and imaginatively titled by
    --  White--Hawk (GH)
    
    --  Thanks to everyone.
    
    
                   ---------------
        ----------||  CONTROLS:  ||--------------
        --         ---------------             --
        --                                     --
        --                                     --
        --  R-Ctrl +                           --
        --      M1      -   Cycle R<>G         --
        --      M2      -   Cycle G<>B         --
        --      M3      -   Cycle B<>R         --
        --                                     --
        --  R-Shift +                          --
        --      M1      -   Cycle RGB          --
        --      M2      -   Cycle RBG          --
        --      M3      -   Colour Picker      --
        --                                     --
        --  While Cycling:                     --
        --  R-Shift +                          --
        --      L-Shift -   Faster             --
        --      L-Ctrl  -   Slower             --
        --                                     --
        --  L-Shift +                          --
        --      R-Ctrl  -   Toggle LHC mode    --
        --                  (G19/G13 sync)     --
        --                                     --
        --  While Picking:                     --
        --  R-Shift/R-Ctrl (brighter/darker) + --
        --      L-Shift -   Red                --
        --      L-Ctrl  -   Green              --
        --      L-Alt   -   Blue               --
        --                                     --
        --  Press any other MKey to stop       --
        --  cycling or picking, and keep       --
        --  selected colour.                   --
        --                                     --
        --                                     --
        -----------------------------------------
    
    --  **Cycle rate:
    --  **(default = 150; red-to-red in ~23secs)
    --  **(always set lower than mrate)
    rate = 150
    
    --  **Minimum delay:
    --  **(default = 600; red-to-red in ~1.5mins)
    --  **(higher is slower)
    mrate = 600
    
    --  **Static (RGB) Colour:
    --  **(default = 140, 255, 150; white on my G19)
    R, G, B = 140, 255, 150
    
    function OnEvent(event,arg)
    
    --    Cycle or set custom colour:
        if (event=="M_PRESSED") and IsModifierPressed("rshift") then
    
    --        Cycle RGB:
            if arg==1 then Cycle(0, 5, 0, 1, arg)
    
    --        Cycle RBG:
            elseif arg==2 then Cycle(255, -5, 2, -1, arg)
    
            else
    
    --            Set custom static colour.  Right Shift/Ctrl(+/-) plus Left-Shift/Ctrl/Alt(R/G/B).
                run=1
                while run~=null do
                    if IsModifierPressed("rshift") then
                        if IsModifierPressed("lshift") then R=R+.1
                            if R>255 then R=255; end
                        end
                        if IsModifierPressed("lctrl") then G=G+.1 
                            if G>255 then G=255; end
                        end
                        if IsModifierPressed("lalt") then B=B+.1
                            if B>255 then B=255; end
                        end
                    elseif IsModifierPressed("rctrl") then
                        if IsModifierPressed("lshift") then R=R-.1
                            if R<0 then R=0; end
                        end
                        if IsModifierPressed("lctrl") then G=G-.1
                            if G<0 then G=0; end
                        end
                        if IsModifierPressed("lalt") then B=B-.1
                            if B<0 then B=0; end
                        end
                    end
                    SetBacklightColor(math.floor(R),math.floor(G),math.floor(B))
                    if (IsModifierPressed("lalt") and IsModifierPressed("ralt")) or GetMKeyState()~=3 then run=null; break; end
                end
    
    --            All done?  Re-set new static colour after profiler applies default one.
                Sleep(350)
                SetBacklightColor(math.floor(R),math.floor(G),math.floor(B))
            end
    
        end
    
    --    Reciprocating fade; Red <> Green or Green <> Blue or Blue <> Red:
        if (event=="M_PRESSED") and IsModifierPressed("rctrl") then Fade(arg); end
    
    end
    
    function Fade(ks)
        fs=0; fj=5; fd=0; run=1
        while run~=null do
    
    --        Ramp colour value 0-255 (and back), or full-off to full-on.
            for col = fs, 255-fs, fj do
    
    --            Call for delay before next colour change.
                Dlay(ks)
    
                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
                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
                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
                end
    
    --            Skip out of ramps...
                if run==null then break; end
    
            end
    
    --        Change direction...
            if fd==0 then fd=1; fs=255; fj=-5
            else fd=0; fs=0; fj=5
    
    --        Skip out of reciprocating fade...
            if run==null then break; end
            end
        end
    end
    
    function Cycle(cs, cj, rs, rj, ks)
        run=1
        while run~=null do
    
    --        Loop through each of R, G, and B.
            for rgb = rs, 2-rs, rj do
    
    --            Ramp colour value 0-255, or full-off to full-on.
                for col = cs, 255-cs, cj do
    
    --                Call for delay before next colour change.
                    Dlay(ks)
    
                    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
                    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
                    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
                    end
    
                    if run==null then break; end
                end
    
    --            Skip out of RGB loops...
                if run==null then break; end
            end
    
        end
    end
    
    function Dlay(ks)
    --    Throttle controls during sleep.
        for z = 1, rate, 1 do
    
    --        Faster...
            if IsModifierPressed("lshift") and IsModifierPressed("rshift") then rate=(rate-(mrate/6000))
                if rate<2 then rate=2
                    if limit~=0 then limit=0; OutputLCDMessage("\n"..(string.rep(" ",37)).."MAXIMUM SPEED!!!", 3000); end
                end
    --            Increments for display...
                dup=math.floor((60/mrate)*rate)
                if nup~=dup then Disp(); end
    
    --        Slower...
            elseif IsModifierPressed("lctrl") and IsModifierPressed("rshift") then rate=(rate+(mrate/6000))
                if rate>mrate then rate=mrate; end
    --            Increments for display...
                dup=math.floor((60/mrate)*rate)
                if nup~=dup or limit~=1 then Disp(); limit=1; end
            end
    
    --        ~333ms control delay...
            if tt==null then tt=0 elseif tt<334 then tt=tt+1 end
            if tt>333 and IsModifierPressed("rctrl") and IsModifierPressed("lshift") then tt=0
                if lmode~="1" then lmode="1" else lmode="0" end
            end
    
    --        Don't wait for delay if another M-key is pressed.
            if GetMKeyState()~=ks or (IsModifierPressed("lalt") and IsModifierPressed("ralt")) then run=null; break; end
            Sleep(1)
    
        end
    end
    
    function Disp()
    --    Draw an incremental slider to G19 LCD output.  It grabs/drops focus rapidly.  :S
        text="\n\n\n\n\n\n        <["..(string.rep("||",60-dup)).."|||"..(string.rep("-",dup)).."]>"
        ClearLCD(); OutputLCDMessage(text, 2000)
        nup=dup
    end

    _______________

    Issues:

    - The scripting display applet doesn't like a lot of data, so it tends to sulk
    if the cycle rate is constantly altered. It works again after a while. This may be
    because spamming the ClearLCD() & OutputLCDMessage commands causes
    the script display to take focus rapidly, triggering a panel manager cool-off.
    It's no big deal, but means the speed indicator won't always show.

    - The RGB value 255, 255, 255 does not look white! On my keyboard,
    despite the white looking good enough when set via the profiler swatches, it
    looks light-purple/pink when set via the script, or by the profiler's RGB picker.
    I think this is just a calibration 'feature', as matching real white requires
    values nearer 140, 255, 150. I can confirm this by setting the colour to white
    with the profiler colour swatches and opening the profiler's RGB picker; it will
    show all values set as 255. Now hit OK without changing a thing and watch the
    keyboard back-light closely.

    - Changing profiles (automatically, for instance, when loading a game or an
    application) can cause the script to lock out the M-keys. Better stop cycling
    before loading another profile. You can do this by changing M state (press one
    of the other M keys) or by pressing both Alt keys together.


    _______________

    Disclaimer:

    While every effort has been made to get this product to you in a satisfactory condition, no guarantees, warranties, liabilities,
    or STDs are accepted, implied, or otherwise conveyed in the granting of permission to use this product freely.

    This product contains no artificial flavours. It may contain nuts.

    Seriously, though; the user of any script accepts responsibility for any adverse conditions or damages caused by the use of it,
    though such a scenario is highly unlikely. Use at your own risk!

    _______________

    Thanks to CRutgerXryzis and Canyon (among others) for the idea. Cheers! ;)
    Last edited by White--Hawk; 02-12-2010 at 01:03 PM. Reason: Colour pimped the post; pixellated, technicolour migraine baby, yeah!

  2. #2
    osten87 is offline Newbie
    Join Date
    Sep 2009
    Posts
    1

    Default

    Wicked!
    I got is to work First time I tried!
    THX M8.

    Although I encounter a weird bug when I was writing with the script turned on.
    The colours started to switch faster and faster the more I pressed the buttons until it almost became psychedelic. :S
    When I stopped and restarted the script it was all back to normal.
    Last edited by osten87; 09-24-2009 at 03:08 PM. Reason: additional info about bug

  3. #3
    White--Hawk is offline G15 Forums GOD
    Join Date
    Aug 2008
    Location
    At home.
    Posts
    1,440

    Default More twiddling...

    LOL! That's not a bug - you were hitting the left shift key. =D

    Left Shift increases the cycle rate, and Left Ctrl decreases the cycle rate. Maximum rate is a shade shift every two milliseconds, which is just psychadelic enough (1ms is almost just flickering white). Minimum is every 250 milliseconds (meaning a good few seconds between colour changes).

    I can see where that left shift key could be a little annoying though, so I shall move these controls to the Left/Right Ctrl keys. ;)

    EDIT: Post updated with new script!

  4. #4
    Interceptor One is offline Admin & Overlay Guru Should be the G15Forum Owner
    Join Date
    Mar 2006
    Location
    Bray, in Wicklow, Ireland
    Posts
    2,527

    Default

    Since the right Control Key is used to access special characters,
    you may wanna re-think that too.
    I'd suggest a key combo, or even better, a user-selectable key combo.

  5. #5
    White--Hawk is offline G15 Forums GOD
    Join Date
    Aug 2008
    Location
    At home.
    Posts
    1,440

    Default

    Thanks Interceptor - you are right, of course. I should have been in bed, asleep, so I was being lazy.

    I've updated it to require right-shift + left-shift/left-ctrl for speed adjustment. This doesn't seem like a key combination that's likely to be used elsewhere. As for making them user selectable - I'm afraid that's beyond the scope of the script as it stands (I've had three days to learn this much).

    The two lines after the comment "check for control keys" can be edited to check for other keys. I stuck with modifiers (shift/ctrl) as holding these won't result in repeated characters in whatever application you might be using at the time.

    Acceptable arguments for IsModifierPressed include "lalt", "ralt", "lshift", "rshift", "lctrl", and "rctrl". Feel free to tweak to taste. :)

    I am at the office, so I don't have access to the hardware. Could anyone let me know if this is working as it should? I'll check it when I get home otherwise.

    I'm thinking of adding R-Shift + M3 to manually cycle through a range of colours (*press* red, *press* orange, *press* yellow, etc)... or maybe ctrl + M1/M2/M3 to shift each colour in the spectrum for manually setting a static colour.

    Ideas welcome. Just don't expect a lot from a three-day-old scripter! ;)
    Last edited by White--Hawk; 09-25-2009 at 07:52 AM. Reason: Waffle... :P

  6. #6
    Interceptor One is offline Admin & Overlay Guru Should be the G15Forum Owner
    Join Date
    Mar 2006
    Location
    Bray, in Wicklow, Ireland
    Posts
    2,527

    Default

    I don't as yet own a G19 (the disadvantages of having been made redundant after 13 years at my old workplace),
    so I can't help with testing anything.
    But it seemed logical to me to use a combo that wouldn't normally be hit during normal keyboard use.

  7. #7
    detiere is offline Newbie
    Join Date
    Sep 2009
    Posts
    2

    Default

    Hi! I just registered and have had my new G19 all of 2 days now. Tried the script and it works hella well. One question though. Is the constant changing of the backlight going to shorten the life expectancy of the keyboard/backlight in any way?

  8. #8
    White--Hawk is offline G15 Forums GOD
    Join Date
    Aug 2008
    Location
    At home.
    Posts
    1,440

    Default Should I include a disclaimer for... a script??

    @ Interceptor One; sorry to hear it. Hard times all round, methinks, and I count myself lucky that I get by, despite things being uncertain at the company for which I work... but more so for the generosity of the missus and a very, very early Christmas present.

    As for the obvious logic, I can only say that a hard week and a sleepless night had somewhat dulled my mental faculties. I'm still grateful for the idea. ;)

    @ Detiere; I think it would be imprudent of me to dismiss your question out of hand, and you've really made me think hard about it now, so perhaps I should include some sort of disclaimer. lol

    I can tell you that LEDs don't just fail, but gradually fade with time. Dimming an LED, even repeatedly, could conceivably extend its lifespan by keeping it below its peak output for a greater portion of time, and reducing the rate of degradation.

    On the other hand, as the cross-fade is entirely linear so that overall output is essentially always at peak, the action of this script could be considered a form of wear-levelling. Rather than having the most used LEDs degrading at a normal rate, all LEDs could be experiencing up to two thirds less wear.

    When LED backlights fail catastrophically, it is likely as a result of electronic failure. On this point I can make no guesses, but I doubt that this script goes beyond the design limits of the provided hardware.

    I have read a few posts about dead LEDs (electronic failure) in relatively new keyboards which highlights a potential for manufacturing faults. I honestly don't believe that this simple script could be held accountable for coincidental failure of Logitech's products.

    I didn't really intend this script to be used persistently to be perfectly honest, hence the lack of forethought in the previous control scheme, but I have been using it constantly since I first typed it up, so it's up to you to decide if you can trust my judgement. ;)

    Sorry for the waffle. Hehe.

  9. #9
    detiere is offline Newbie
    Join Date
    Sep 2009
    Posts
    2

    Default

    @White--Hawk: Thank you for the well thought out response. To be perfectly honest, I'm not entirely worried about it, it was more of a general thought, as I was watching the awesome that was my ever-changing keyboard color, that it might be putting extra wear on it. This is overall an awesome script that will be sure to please any of my curious friends that just come by wondering what that keyboard is that will let you watch youtube videos on it. :)

    Keep up the great work!

  10. #10
    Chong McBong is offline Beta Member
    Join Date
    Jun 2009
    Location
    Cybertron
    Posts
    30

    Default

    very nice script :)
    See my 3D models for GTA San Andreas here:
    http://sites.google.com/site/diewreckt/home

    Control Systems for my "Monolithic Monstrosity" PC:
    Logitech G19 Keyboard
    Logitech G13 Gameboard
    Logitech MX1000 Mouse (x2)

Page 1 of 12 12311 ... LastLast

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •