Toggle Navigation
Hatchery
Eggs
Hotkeys
__init__.py
Users
Badges
Login
Register
MCH2022 badge?
go to mch2022.badge.team
__init__.py
raw
Content
import hid, keypad, display, time, appconfig # TODO from keycodes import * settings = appconfig.get('hotkeys', {'option_1': 'defaultvalue', 'awesomeness': 1337, 'option_3': [1,2,3]}) mynumber = settings['awesomeness'] KEY_LEFTCTRL = 0xe0 # Keyboard Left Control KEY_LEFTSHIFT = 0xe1 # Keyboard Left Shift KEY_LEFTALT = 0xe2 # Keyboard Left Alt KEY_LEFTMETA = 0xe3 # Keyboard Left GUI KEY_A = 0x04 # Keyboard a and A global brightness brightness = 1 # anything between 0-25 def draw_col(x, y, value, r, g, b): col = int('0x{}{}{}'.format(value if r else '00', value if g else '00', value if b else '00'), 16) display.drawPixel(x, y, col) def draw_display(): global brightness value = '{:02x}'.format(10*brightness) draw_col(0,0, value, True, False, False) draw_col(1,0, value, False, True, False) draw_col(2,0, value, False, False, True) draw_col(3,0, value, True, True, False) draw_col(0,1, value, True, False, True) draw_col(1,1, value, False, True, True) if brightness <= 25: brighter = '{:02x}'.format(10*(brightness)) else: brighter = '00' if brightness > 0: dimmer = '{:02x}'.format(10*(brightness-1)) else: dimmer = '00' draw_col(3,2, brighter, True, True, True) draw_col(3,3, dimmer, True, True, True) display.flush() draw_display() def press(x,y,keys,value,bright,r,g,b): draw_col(x,y, bright, r, g, b) display.flush() hid.keyboard_press_keys(bytes(keys)) time.sleep(.100) hid.keyboard_release() draw_col(x,y, value, r, g, b) def on_key(key_index, pressed): global brightness x, y = key_index % 4, int(key_index / 4) if(pressed): value = hex(10*brightness)[2:] bright = hex(10*(brightness+1))[2:] if (x,y) == (0,0): press(x,y,[KEY_LEFTCTRL, KEY_A],value,bright,True,False,False) # draw_col(x,y, bright, True, False, False) if x == 3 and y == 2: if brightness < 25: brightness += 1 draw_display() if x == 3 and y == 3: if brightness > 0: brightness -= 1 draw_display() display.flush() keypad.add_handler(on_key)