Skip to content

Instantly share code, notes, and snippets.

@rigaspapas
Last active March 5, 2017 15:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rigaspapas/5da713b4722be6728d89bdb7841c03be to your computer and use it in GitHub Desktop.
Save rigaspapas/5da713b4722be6728d89bdb7841c03be to your computer and use it in GitHub Desktop.
A Python script that reflect the screen's image to your Corsair RGB keyboard
# CUE SDK from: https://github.com/10se1ucgo/cue_sdk
from cue_sdk import *
# Pillow library: https://pillow.readthedocs.io/en/4.0.x/
import ImageGrab
import os
import time
# Setup the keys matrix
keys = [['Escape', 'F1', 'F2', 'F3', 'F4', 'F5', 'F6', 'F7', 'F8', 'F9', 'F10', 'F11', 'F12'],
['GraveAccentAndTilde', '_1', '_2', '_3', '_4', '_5', '_6', '_7', '_8', '_9', '_0', 'MinusAndUnderscore', 'EqualsAndPlus', 'Backspace'],
['Tab', 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', 'BracketLeft', 'BracketRight', 'Enter'],
['CapsLock', 'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', 'SemicolonAndColon', 'ApostropheAndDoubleQuote', 'NonUsTilde'],
['LeftShift', 'NonUsBackslash', 'Z', 'X', 'C', 'V', 'B', 'N', 'M', 'CommaAndLessThan', 'PeriodAndBiggerThan', 'SlashAndQuestionMark', 'RightShift'],
['LeftCtrl', 'LeftGui', 'LeftAlt', 'Space','Space','Space','Space','Space', 'RightAlt', 'RightGui', 'Application', 'RightCtrl']]
os.chdir('{{PATH_TO_CUESDK_DLL}}')
Corsair = CUESDK("CUESDK_2015.dll")
if Corsair.RequestControl(CAM.ExclusiveLightingControl):
while True:
# Take a screenshot and create a thumbnail out from it
ss = ImageGrab.grab()
# My screen has 21:9 ratio, define the dimensions that match yours
ss.thumbnail((15, 6))
# Set each key color according to the thumbnail
for y in xrange(0, len(keys)):
for x in xrange(0, len(keys[y])):
color = ss.getpixel((x, y))
Corsair.set_led_colors(CorsairLedColor(getattr(CLK, keys[y][x]), color[0], color[1], color[2]))
# Remove for non-stop refresh
time.sleep(.5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment