Skip to content

Instantly share code, notes, and snippets.

@illixion
Last active June 6, 2023 06:26
Show Gist options
  • Save illixion/b4027442bd5d55885881a6f8da9a4fb4 to your computer and use it in GitHub Desktop.
Save illixion/b4027442bd5d55885881a6f8da9a4fb4 to your computer and use it in GitHub Desktop.
import win32con
import win32api
import win32gui
import time
import socket
from openrgb import OpenRGBClient
from openrgb.utils import DeviceType
# While port 6742 is open
while True:
try:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind(("localhost", 6742))
s.close()
time.sleep(10)
except socket.error:
break
cli = OpenRGBClient()
cli.connect()
def turn_off_ram_leds():
for dev in cli.devices:
if dev.type == DeviceType.DRAM:
dev.set_mode("off")
def turn_on_ram_leds():
for dev in cli.devices:
if dev.type == DeviceType.DRAM:
dev.set_mode("rainbow")
# dev.set_mode("random flicker")
def wndproc(hwnd, msg, wparam, lparam):
if msg == win32con.WM_POWERBROADCAST:
if wparam == win32con.PBT_APMSUSPEND:
print("WM_POWERBROADCAST: PBT_APMSUSPEND")
turn_off_ram_leds()
return True
elif wparam == win32con.PBT_APMRESUMEAUTOMATIC:
print("WM_POWERBROADCAST: PBT_APMRESUMEAUTOMATIC")
turn_on_ram_leds()
return True
else:
print("WM_POWERBROADCAST: Other (%s)" % wparam)
return True
if __name__ == "__main__":
hinst = win32api.GetModuleHandle(None)
wndclass = win32gui.WNDCLASS()
wndclass.hInstance = hinst
wndclass.lpszClassName = "testWindowClass"
messageMap = {
win32con.WM_POWERBROADCAST: wndproc,
win32con.WM_QUIT: wndproc,
win32con.WM_DESTROY: wndproc,
win32con.WM_CLOSE: wndproc,
}
wndclass.lpfnWndProc = messageMap
try:
myWindowClass = win32gui.RegisterClass(wndclass)
hwnd = win32gui.CreateWindowEx(
win32con.WS_EX_LEFT,
myWindowClass,
"testMsgWindow",
0,
0,
0,
win32con.CW_USEDEFAULT,
win32con.CW_USEDEFAULT,
0,
0,
hinst,
None,
)
except Exception as e:
print("Exception: %s" % str(e))
if hwnd is None:
print("hwnd is none!")
else:
print("hwnd: %s" % hwnd)
while True:
win32gui.PumpWaitingMessages()
time.sleep(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment