2023-07-27 22:47:59 +00:00
# from discord: and about the layers getting stuck, i found out that if you accidentally hit two keys that are layer keys, and they dont have a combo between them, they gonna get stuck
2023-04-19 15:50:56 +00:00
import os
2023-04-19 16:03:27 +00:00
2023-04-19 12:31:18 +00:00
import board
2023-04-19 15:50:56 +00:00
from kmk . kmk_keyboard import KMKKeyboard
2023-04-19 19:33:07 +00:00
from kmk . keys import KC
2023-07-30 13:45:20 +00:00
from ardux . chord import ArduxChord # FIXME: Need to fix ArduxChord / sort layer filters for combos
2023-04-19 19:33:07 +00:00
2023-04-19 15:50:56 +00:00
from kmk . modules . layers import Layers
from kmk . modules . combos import Combos , Chord
2023-07-27 22:47:59 +00:00
from kmk . modules . holdtap import HoldTap
2023-04-19 22:10:24 +00:00
from kmk . modules . oneshot import OneShot
2023-04-19 16:38:01 +00:00
from kmk . modules . mouse_keys import MouseKeys
from kmk . extensions . media_keys import MediaKeys
2023-04-19 12:31:18 +00:00
2023-04-19 19:33:07 +00:00
# constants
LAYER_ID_BASE = 0
LAYER_ID_PARENS = 1
LAYER_ID_NUMBERS = 2
LAYER_ID_NAVIGATION = 3
LAYER_ID_SYMBOLS = 4
LAYER_ID_CUSTOM = 5
LAYER_ID_MOUSE = 6
2023-04-19 12:31:18 +00:00
2023-07-30 13:45:20 +00:00
class _ArduxKeyboard ( KMKKeyboard ) :
2023-04-19 12:31:18 +00:00
coord_mapping = [
0 , 1 , 2 , 3 ,
4 , 5 , 6 , 7 ,
]
2023-04-19 15:50:56 +00:00
2023-04-19 19:33:07 +00:00
keymap = [ ]
2023-04-19 15:50:56 +00:00
2023-07-30 13:45:20 +00:00
# Switch to ABC python3 stl abstract class methods
# See https://stackoverflow.com/a/4382964 for detail (the accepted answer)
2023-07-30 13:26:00 +00:00
def setup_physical_config ( self ) :
2023-07-30 13:45:20 +00:00
raise NotImplementedError ( ' Please define the physical config for your keyboard ' )
2023-07-30 13:26:00 +00:00
2023-04-19 15:50:56 +00:00
# Init / constructor / setup
def __init__ ( self ) :
# Enable debugging if appropriate
if os . getenv ( ' ARDUX_KMK_DEBUGGING ' ) :
self . debug_enabled = True
# setup modules/extensions arrays
self . modules = [ ]
self . extensions = [ ]
2023-07-27 22:47:59 +00:00
2023-07-30 13:26:00 +00:00
# Call setup hook -- matrix/direct wire config
self . setup_physical_config ( )
2023-04-19 15:50:56 +00:00
2023-07-27 22:47:59 +00:00
# Layers
self . layers_module = Layers ( )
self . layers_module . prefer_hold = False
self . layers_module . tap_interrupted = True
self . modules . append ( self . layers_module )
# Combos
self . combo_module = Combos ( )
self . combo_module . prefer_hold = True
self . combo_module . tap_interrupted = False
self . modules . append ( self . combo_module )
2023-04-19 19:33:07 +00:00
# HoldTap
self . holdtap_module = HoldTap ( )
2023-07-27 22:47:59 +00:00
self . holdtap_module . tap_time = 50
self . holdtap_module . prefer_hold = True
2023-04-19 19:33:07 +00:00
self . modules . append ( self . holdtap_module )
2023-07-27 22:47:59 +00:00
# One Shot
self . modules . append ( OneShot ( ) )
2023-04-19 15:50:56 +00:00
2023-04-19 16:38:01 +00:00
# Media Keys
self . extensions . append ( MediaKeys ( ) )
# Mouse Keys
self . modules . append ( MouseKeys ( ) )
2023-04-19 19:33:07 +00:00
# Setup kemap as last step
self . setup_keymap ( )
# Setup combos
2023-04-19 15:50:56 +00:00
self . setup_combos ( )
2023-04-19 19:33:07 +00:00
# Define keymap
def setup_keymap ( self ) :
2023-07-27 22:47:59 +00:00
self . base_s_numbers = KC . LT ( LAYER_ID_NUMBERS , KC . S )
self . base_a_parens = KC . LT ( LAYER_ID_PARENS , KC . A )
self . base_o_custom = KC . LT ( LAYER_ID_CUSTOM , KC . O )
self . base_e_symbols = KC . LT ( LAYER_ID_SYMBOLS , KC . E )
2023-04-19 19:33:07 +00:00
self . keymap = [
# std - left - base
[ self . base_s_numbers , KC . T , KC . R , self . base_a_parens ,
self . base_o_custom , KC . I , KC . Y , self . base_e_symbols ] ,
# std - left - parenthesis
[ KC . RIGHT_CURLY_BRACE , KC . LEFT_PAREN , KC . RIGHT_PAREN , KC . TRANSPARENT ,
KC . LEFT_CURLY_BRACE , KC . LBRACKET , KC . RBRACKET , KC . NO ] ,
# std - left - number
[ KC . TRANSPARENT , KC . N3 , KC . N2 , KC . N1 ,
KC . NO , KC . N6 , KC . N5 , KC . N4 ] ,
# std - left - navigation
2023-04-19 20:19:49 +00:00
[ KC . PGUP , KC . HOME , KC . UP , KC . END ,
2023-04-19 19:33:07 +00:00
KC . PGDOWN , KC . LEFT , KC . DOWN , KC . RIGHT ] ,
# std - left - symbols
[ KC . GRAVE , KC . SCOLON , KC . BSLASH , KC . EXCLAIM ,
KC . EQUAL , KC . MINUS , KC . QUESTION , KC . TRANSPARENT ] ,
# std - left - custom
[ KC . NO , KC . AUDIO_VOL_UP , KC . INSERT , KC . AUDIO_MUTE ,
KC . TRANSPARENT , KC . AUDIO_VOL_DOWN , KC . PSCREEN , KC . RSHIFT ] ,
# std - left - mouse
2023-04-19 20:19:49 +00:00
[ KC . MW_UP , KC . MB_RMB , KC . MS_UP , KC . MB_LMB ,
KC . MW_DOWN , KC . MS_LEFT , KC . MS_DN , KC . MS_RIGHT ]
2023-04-19 19:33:07 +00:00
]
2023-04-19 15:50:56 +00:00
# Define combos for ardux
def setup_combos ( self ) :
self . combo_module . combos = [ ]
2023-04-19 20:19:49 +00:00
2023-04-19 21:46:24 +00:00
#####
2023-04-19 20:19:49 +00:00
# std - base
2023-04-19 21:46:24 +00:00
# layers
2023-07-27 22:47:59 +00:00
self . combo_module . combos . append ( Chord ( ( KC . R , KC . I , self . base_e_symbols ) , KC . TO ( LAYER_ID_NAVIGATION ) ) )
self . combo_module . combos . append ( Chord ( ( KC . T , KC . Y , self . base_a_parens ) , KC . TO ( LAYER_ID_MOUSE ) ) )
2023-04-19 22:10:24 +00:00
# mods
2023-07-27 22:47:59 +00:00
self . combo_module . combos . append ( Chord ( ( self . base_s_numbers , self . base_e_symbols ) , KC . OS ( KC . LCTRL ) ) )
self . combo_module . combos . append ( Chord ( ( KC . Y , self . base_s_numbers ) , KC . OS ( KC . LGUI ) ) )
self . combo_module . combos . append ( Chord ( ( KC . I , self . base_s_numbers ) , KC . OS ( KC . LALT ) ) )
self . combo_module . combos . append ( Chord ( ( self . base_s_numbers , KC . R , KC . T , self . base_e_symbols ) , KC . OS ( KC . LSHIFT ) ) )
2023-04-19 21:46:24 +00:00
# control sequences
2023-07-27 22:47:59 +00:00
self . combo_module . combos . append ( Chord ( ( self . base_o_custom , KC . I , KC . Y , self . base_e_symbols ) , KC . SPACE ) )
self . combo_module . combos . append ( Chord ( ( self . base_a_parens , KC . R , self . base_o_custom ) , KC . ESCAPE ) )
self . combo_module . combos . append ( Chord ( ( self . base_e_symbols , KC . R ) , KC . BSPACE ) )
self . combo_module . combos . append ( Chord ( ( KC . R , KC . I ) , KC . DELETE ) )
self . combo_module . combos . append ( Chord ( ( self . base_a_parens , KC . R , KC . T , self . base_o_custom ) , KC . TAB ) )
self . combo_module . combos . append ( Chord ( ( self . base_a_parens , self . base_e_symbols ) , KC . ENTER ) )
self . combo_module . combos . append ( Chord ( ( self . base_a_parens , KC . Y , KC . I , self . base_o_custom ) , KC . CAPSLOCK ) )
2023-04-19 21:46:24 +00:00
# symbols
2023-07-27 22:47:59 +00:00
self . combo_module . combos . append ( Chord ( ( self . base_a_parens , KC . Y ) , KC . DOT ) )
self . combo_module . combos . append ( Chord ( ( self . base_a_parens , KC . I ) , KC . COMMA ) )
self . combo_module . combos . append ( Chord ( ( self . base_a_parens , self . base_o_custom ) , KC . SLASH ) )
self . combo_module . combos . append ( Chord ( ( self . base_a_parens , KC . Y , KC . I ) , KC . QUOTE ) )
2023-04-19 21:46:24 +00:00
# ansi
2023-07-27 22:47:59 +00:00
self . combo_module . combos . append ( Chord ( ( self . base_o_custom , self . base_e_symbols ) , KC . B ) )
self . combo_module . combos . append ( Chord ( ( self . base_e_symbols , KC . Y ) , KC . C ) )
self . combo_module . combos . append ( Chord ( ( KC . I , self . base_o_custom ) , KC . N ) )
self . combo_module . combos . append ( Chord ( ( self . base_a_parens , KC . R ) , KC . F ) )
self . combo_module . combos . append ( Chord ( ( KC . R , KC . T ) , KC . G ) )
self . combo_module . combos . append ( Chord ( ( KC . Y , KC . I ) , KC . U ) )
self . combo_module . combos . append ( Chord ( ( self . base_e_symbols , KC . I ) , KC . H ) )
self . combo_module . combos . append ( Chord ( ( KC . R , self . base_s_numbers ) , KC . V ) )
self . combo_module . combos . append ( Chord ( ( KC . T , self . base_s_numbers ) , KC . J ) )
self . combo_module . combos . append ( Chord ( ( self . base_a_parens , self . base_s_numbers ) , KC . W ) )
self . combo_module . combos . append ( Chord ( ( KC . Y , self . base_o_custom ) , KC . K ) )
self . combo_module . combos . append ( Chord ( ( KC . Y , KC . I , self . base_o_custom ) , KC . M ) )
self . combo_module . combos . append ( Chord ( ( self . base_a_parens , KC . R , KC . T ) , KC . D ) )
self . combo_module . combos . append ( Chord ( ( self . base_o_custom , KC . I , self . base_e_symbols ) , KC . P ) )
self . combo_module . combos . append ( Chord ( ( self . base_a_parens , KC . T , self . base_s_numbers ) , KC . Q ) )
self . combo_module . combos . append ( Chord ( ( KC . R , KC . T , self . base_s_numbers ) , KC . X ) )
self . combo_module . combos . append ( Chord ( ( KC . I , KC . Y , self . base_e_symbols ) , KC . L ) )
self . combo_module . combos . append ( Chord ( ( self . base_a_parens , KC . R , KC . T , self . base_s_numbers ) , KC . Z ) )
2023-04-19 21:46:24 +00:00
#####
2023-04-19 20:19:49 +00:00
# std - nav
2023-07-27 22:47:59 +00:00
self . combo_module . combos . append ( Chord ( ( KC . UP , KC . LEFT , KC . RIGHT ) , KC . TO ( LAYER_ID_BASE ) ) )
self . combo_module . combos . append ( Chord ( ( KC . END , KC . RIGHT ) , KC . ENTER ) )
self . combo_module . combos . append ( Chord ( ( KC . END , KC . UP , KC . PGDOWN ) , KC . ESCAPE ) )
self . combo_module . combos . append ( Chord ( ( KC . RIGHT , KC . UP ) , KC . BSPACE ) )
self . combo_module . combos . append ( Chord ( ( KC . UP , KC . LEFT ) , KC . DELETE ) )
self . combo_module . combos . append ( Chord ( ( KC . END , KC . UP , KC . HOME , KC . PGDOWN ) , KC . TAB ) )
self . combo_module . combos . append ( Chord ( ( KC . RIGHT , KC . DOWN , KC . LEFT , KC . PGDOWN ) , KC . SPACE ) )
self . combo_module . combos . append ( Chord ( ( KC . RIGHT , KC . PGUP ) , KC . OS ( KC . LCTRL ) ) )
self . combo_module . combos . append ( Chord ( ( KC . DOWN , KC . PGUP ) , KC . OS ( KC . LGUI ) ) )
self . combo_module . combos . append ( Chord ( ( KC . LEFT , KC . PGUP ) , KC . OS ( KC . LALT ) ) )
self . combo_module . combos . append ( Chord ( ( KC . RIGHT , KC . UP , KC . HOME , KC . PGUP ) , KC . OS ( KC . LSHIFT ) ) )
2023-04-19 21:46:24 +00:00
#####
# std - number
2023-07-27 22:47:59 +00:00
self . combo_module . combos . append ( Chord ( ( KC . N1 , KC . N2 ) , KC . N7 ) )
self . combo_module . combos . append ( Chord ( ( KC . N2 , KC . N3 ) , KC . N8 ) )
self . combo_module . combos . append ( Chord ( ( KC . N4 , KC . N5 ) , KC . N9 ) )
self . combo_module . combos . append ( Chord ( ( KC . N5 , KC . N6 ) , KC . N0 ) )
self . combo_module . combos . append ( Chord ( ( KC . N1 , KC . N5 ) , KC . DOT ) )
self . combo_module . combos . append ( Chord ( ( KC . N1 , KC . N6 ) , KC . COMMA ) )
self . combo_module . combos . append ( Chord ( ( KC . N1 , KC . N4 ) , KC . ENTER ) )
self . combo_module . combos . append ( Chord ( ( KC . N2 , KC . N6 ) , KC . DELETE ) )
self . combo_module . combos . append ( Chord ( ( KC . N4 , KC . N2 ) , KC . BSPACE ) )
2023-04-19 21:46:24 +00:00
#####
2023-04-19 20:19:49 +00:00
# std - mouse
2023-07-27 22:47:59 +00:00
self . combo_module . combos . append ( Chord ( ( KC . MB_RMB , KC . MS_DN , KC . MB_LMB ) , KC . TO ( LAYER_ID_BASE ) ) )
2023-07-30 14:39:23 +00:00
# work around a bug with combo handling and layer selections in kmk
# these combos should be removed if/when kmk stops 'going hayware' or 'getting stuck' when these key combos are pressed when the below are not in the code
self . combo_module . combos . append ( Chord ( ( self . base_o_custom , KC . Y , self . base_e_symbols ) , KC . NO ) )
self . combo_module . combos . append ( Chord ( ( self . base_a_parens , KC . R , self . base_s_numbers ) , KC . NO ) )
self . combo_module . combos . append ( Chord ( ( self . base_a_parens , KC . T ) , KC . NO ) )