Epic keycode cleanup; make modifiers callable and chainable
This commit is contained in:
parent
85cdf03572
commit
99573de217
@ -23,6 +23,14 @@ class ModifierKeycode:
|
||||
def __init__(self, code):
|
||||
self.code = code
|
||||
|
||||
def __call__(self, modified_code):
|
||||
new_keycode = Keycode(modified_code.code, {self.code})
|
||||
|
||||
if modified_code.has_modifiers:
|
||||
new_keycode.has_modifiers |= modified_code.has_modifiers
|
||||
|
||||
return new_keycode
|
||||
|
||||
|
||||
class ConsumerKeycode:
|
||||
def __init__(self, code):
|
||||
@ -123,13 +131,6 @@ CODE_RALT = 0x40
|
||||
CODE_RGUI = CODE_RCMD = CODE_RWIN = 0x80
|
||||
|
||||
|
||||
class Keycodes(KeycodeCategory):
|
||||
'''
|
||||
A massive grouping of keycodes
|
||||
|
||||
Some of these are from http://www.freebsddiary.org/APC/usb_hid_usages.php,
|
||||
one of the most useful pages on the interwebs for HID stuff, apparently.
|
||||
'''
|
||||
class Modifiers(KeycodeCategory):
|
||||
KC_LCTRL = KC_LCTL = ModifierKeycode(CODE_LCTRL)
|
||||
KC_LSHIFT = KC_LSFT = ModifierKeycode(CODE_LSHIFT)
|
||||
@ -140,6 +141,7 @@ class Keycodes(KeycodeCategory):
|
||||
KC_RALT = ModifierKeycode(CODE_RALT)
|
||||
KC_RGUI = KC_RCMD = KC_RWIN = ModifierKeycode(CODE_RGUI)
|
||||
|
||||
|
||||
class Common(KeycodeCategory):
|
||||
KC_A = Keycode(4)
|
||||
KC_B = Keycode(5)
|
||||
@ -200,6 +202,31 @@ class Keycodes(KeycodeCategory):
|
||||
KC_DOT = Keycode(55)
|
||||
KC_SLASH = KC_SLSH = Keycode(56)
|
||||
|
||||
|
||||
class ShiftedKeycodes(KeycodeCategory):
|
||||
KC_TILDE = KC_TILD = Modifiers.KC_LSHIFT(Common.KC_GRAVE)
|
||||
KC_EXCLAIM = KC_EXLM = Modifiers.KC_LSHIFT(Common.KC_1)
|
||||
KC_AT = Modifiers.KC_LSHIFT(Common.KC_2)
|
||||
KC_HASH = Modifiers.KC_LSHIFT(Common.KC_3)
|
||||
KC_DOLLAR = KC_DLR = Modifiers.KC_LSHIFT(Common.KC_4)
|
||||
KC_PERCENT = KC_PERC = Modifiers.KC_LSHIFT(Common.KC_5)
|
||||
KC_CIRCUMFLEX = KC_CIRC = Modifiers.KC_LSHIFT(Common.KC_6) # The ^ Symbol
|
||||
KC_AMPERSAND = KC_AMPR = Modifiers.KC_LSHIFT(Common.KC_7)
|
||||
KC_ASTERISK = KC_ASTR = Modifiers.KC_LSHIFT(Common.KC_8)
|
||||
KC_LEFT_PAREN = KC_LPRN = Modifiers.KC_LSHIFT(Common.KC_9)
|
||||
KC_RIGHT_PAREN = KC_RPRN = Modifiers.KC_LSHIFT(Common.KC_0)
|
||||
KC_UNDERSCORE = KC_UNDS = Modifiers.KC_LSHIFT(Common.KC_MINUS)
|
||||
KC_PLUS = Modifiers.KC_LSHIFT(Common.KC_EQUAL)
|
||||
KC_LEFT_CURLY_BRACE = KC_LCBR = Modifiers.KC_LSHIFT(Common.KC_LBRACKET)
|
||||
KC_RIGHT_CURLY_BRACE = KC_RCBR = Modifiers.KC_LSHIFT(Common.KC_RBRACKET)
|
||||
KC_PIPE = Modifiers.KC_LSHIFT(Common.KC_BACKSLASH)
|
||||
KC_COLON = KC_COLN = Modifiers.KC_LSHIFT(Common.KC_SEMICOLON)
|
||||
KC_DOUBLE_QUOTE = KC_DQUO = KC_DQT = Modifiers.KC_LSHIFT(Common.KC_QUOTE)
|
||||
KC_LEFT_ANGLE_BRACKET = KC_LABK = KC_LT = Modifiers.KC_LSHIFT(Common.KC_COMMA)
|
||||
KC_RIGHT_ANGLE_BRACKET = KC_RABK = KC_GT = Modifiers.KC_LSHIFT(Common.KC_DOT)
|
||||
KC_QUESTION = KC_QUES = Modifiers.KC_LSHIFT(Common.KC_DOT)
|
||||
|
||||
|
||||
class FunctionKeys(KeycodeCategory):
|
||||
KC_F1 = Keycode(58)
|
||||
KC_F2 = Keycode(59)
|
||||
@ -226,6 +253,7 @@ class Keycodes(KeycodeCategory):
|
||||
KC_F23 = Keycode(114)
|
||||
KC_F24 = Keycode(115)
|
||||
|
||||
|
||||
class NavAndLocks(KeycodeCategory):
|
||||
KC_CAPS_LOCK = KC_CLCK = KC_CAPS = Keycode(57)
|
||||
KC_LOCKING_CAPS = KC_LCAP = Keycode(130)
|
||||
@ -244,6 +272,7 @@ class Keycodes(KeycodeCategory):
|
||||
KC_DOWN = Keycode(81)
|
||||
KC_UP = Keycode(82)
|
||||
|
||||
|
||||
class Numpad(KeycodeCategory):
|
||||
KC_NUMLOCK = KC_NLCK = Keycode(83)
|
||||
KC_LOCKING_NUM = KC_LNUM = Keycode(131)
|
||||
@ -267,6 +296,7 @@ class Keycodes(KeycodeCategory):
|
||||
KC_KP_COMMA = KC_PCMM = Keycode(133)
|
||||
KC_KP_EQUAL_AS400 = Keycode(134)
|
||||
|
||||
|
||||
class International(KeycodeCategory):
|
||||
KC_INT1 = KC_RO = Keycode(135)
|
||||
KC_INT2 = KC_KANA = Keycode(136)
|
||||
@ -287,6 +317,7 @@ class Keycodes(KeycodeCategory):
|
||||
KC_LANG8 = Keycode(151)
|
||||
KC_LANG9 = Keycode(152)
|
||||
|
||||
|
||||
class Misc(KeycodeCategory):
|
||||
KC_APPLICATION = KC_APP = ConsumerKeycode(101)
|
||||
KC_POWER = ConsumerKeycode(102)
|
||||
@ -327,6 +358,7 @@ class Keycodes(KeycodeCategory):
|
||||
KC_WWW_REFRESH = KC_WREF = ConsumerKeycode(185)
|
||||
KC_WWW_FAVORITES = KC_WFAV = ConsumerKeycode(186)
|
||||
|
||||
|
||||
class Media(KeycodeCategory):
|
||||
# I believe QMK used these double-underscore codes for MacOS
|
||||
# support or something. I have no idea, but modern MacOS supports
|
||||
@ -347,6 +379,7 @@ class Keycodes(KeycodeCategory):
|
||||
KC_MEDIA_FAST_FORWARD = KC_MFFD = ConsumerKeycode(179) # 0xB3
|
||||
KC_MEDIA_REWIND = KC_MRWD = ConsumerKeycode(180) # 0xB4
|
||||
|
||||
|
||||
class KMK(KeycodeCategory):
|
||||
KC_RESET = Keycode(1000)
|
||||
KC_DEBUG = Keycode(1001)
|
||||
@ -358,6 +391,7 @@ class Keycodes(KeycodeCategory):
|
||||
KC_NO = Keycode(1107)
|
||||
KC_TRANSPARENT = KC_TRNS = Keycode(1108)
|
||||
|
||||
|
||||
class Layers(KeycodeCategory):
|
||||
_KC_DF = 1050
|
||||
_KC_MO = 1051
|
||||
@ -369,54 +403,52 @@ class Keycodes(KeycodeCategory):
|
||||
|
||||
@staticmethod
|
||||
def KC_DF(layer):
|
||||
return LayerKeycode(Keycodes.Layers._KC_DF, layer)
|
||||
return LayerKeycode(Layers._KC_DF, layer)
|
||||
|
||||
@staticmethod
|
||||
def KC_MO(layer):
|
||||
return LayerKeycode(Keycodes.Layers._KC_MO, layer)
|
||||
return LayerKeycode(Layers._KC_MO, layer)
|
||||
|
||||
@staticmethod
|
||||
def KC_LM(layer):
|
||||
return LayerKeycode(Keycodes.Layers._KC_LM, layer)
|
||||
return LayerKeycode(Layers._KC_LM, layer)
|
||||
|
||||
@staticmethod
|
||||
def KC_LT(layer):
|
||||
return LayerKeycode(Keycodes.Layers._KC_LT, layer)
|
||||
return LayerKeycode(Layers._KC_LT, layer)
|
||||
|
||||
@staticmethod
|
||||
def KC_TG(layer):
|
||||
return LayerKeycode(Keycodes.Layers._KC_TG, layer)
|
||||
return LayerKeycode(Layers._KC_TG, layer)
|
||||
|
||||
@staticmethod
|
||||
def KC_TO(layer):
|
||||
return LayerKeycode(Keycodes.Layers._KC_TO, layer)
|
||||
return LayerKeycode(Layers._KC_TO, layer)
|
||||
|
||||
@staticmethod
|
||||
def KC_TT(layer):
|
||||
return LayerKeycode(Keycodes.Layers._KC_TT, layer)
|
||||
return LayerKeycode(Layers._KC_TT, layer)
|
||||
|
||||
class ShiftedKeycodes(KeycodeCategory):
|
||||
KC_TILDE = KC_TILD = Keycode(53, (CODE_LSHIFT,))
|
||||
KC_EXCLAIM = KC_EXLM = Keycode(30, (CODE_LSHIFT,))
|
||||
KC_AT = Keycode(31, (CODE_LSHIFT,))
|
||||
KC_HASH = Keycode(32, (CODE_LSHIFT,))
|
||||
KC_DOLLAR = KC_DLR = Keycode(33, (CODE_LSHIFT,))
|
||||
KC_PERCENT = KC_PERC = Keycode(34, (CODE_LSHIFT,))
|
||||
KC_CIRCUMFLEX = KC_CIRC = Keycode(35, (CODE_LSHIFT,)) # The ^ Symbol
|
||||
KC_AMPERSAND = KC_AMPR = Keycode(36, (CODE_LSHIFT,))
|
||||
KC_ASTERISK = KC_ASTR = Keycode(37, (CODE_LSHIFT,))
|
||||
KC_LEFT_PAREN = KC_LPRN = Keycode(38, (CODE_LSHIFT,))
|
||||
KC_RIGHT_PAREN = KC_RPRN = Keycode(39, (CODE_LSHIFT,))
|
||||
KC_UNDERSCORE = KC_UNDS = Keycode(45, (CODE_LSHIFT,))
|
||||
KC_PLUS = Keycode(46, (CODE_LSHIFT,))
|
||||
KC_LEFT_CURLY_BRACE = KC_LCBR = Keycode(47, (CODE_LSHIFT,))
|
||||
KC_RIGHT_CURLY_BRACE = KC_RCBR = Keycode(48, (CODE_LSHIFT,))
|
||||
KC_PIPE = Keycode(49, (CODE_LSHIFT,))
|
||||
KC_COLON = KC_COLN = Keycode(51, (CODE_LSHIFT,))
|
||||
KC_DOUBLE_QUOTE = KC_DQUO = KC_DQT = Keycode(52, (CODE_LSHIFT,))
|
||||
KC_LEFT_ANGLE_BRACKET = KC_LABK = KC_LT = Keycode(54, (CODE_LSHIFT,))
|
||||
KC_RIGHT_ANGLE_BRACKET = KC_RABK = KC_GT = Keycode(55, (CODE_LSHIFT,))
|
||||
KC_QUESTION = KC_QUES = Keycode(56, (CODE_LSHIFT,))
|
||||
|
||||
class Keycodes(KeycodeCategory):
|
||||
'''
|
||||
A massive grouping of keycodes
|
||||
|
||||
Some of these are from http://www.freebsddiary.org/APC/usb_hid_usages.php,
|
||||
one of the most useful pages on the interwebs for HID stuff, apparently.
|
||||
'''
|
||||
|
||||
Modifiers = Modifiers
|
||||
Common = Common
|
||||
ShiftedKeycodes = ShiftedKeycodes
|
||||
FunctionKeys = FunctionKeys
|
||||
NavAndLocks = NavAndLocks
|
||||
Numpad = Numpad
|
||||
International = International
|
||||
Misc = Misc
|
||||
Media = Media
|
||||
KMK = KMK
|
||||
Layers = Layers
|
||||
|
||||
|
||||
ALL_KEYS = KC = AttrDict({
|
||||
|
Loading…
x
Reference in New Issue
Block a user