Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#include "keymap_common.h"
#include <util/delay.h>
#include "wait.h"
const uint8_t keymaps[][MATRIX_ROWS][MATRIX_COLS] PROGMEM = {
KEYMAP(
ESC, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, MINS, EQL, BSPC,/*14X*/
TAB, Q, W, E, R, T, Y,FN11, FN5,FN12, P, FN8, FN9, FN30,/*14X*/
LCTL,A,FN13, D, F,FN14, H, J, K, L,SCLN, FN7, ENT, /*13X*/
LSHIFT, Z, X,FN15, V, B, N, M, FN25,FN26, SLSH, UP, FN10,/*13X*/
LALT,LGUI, SPC, FN2, LEFT, DOWN, RGHT /*7X*/
),
KEYMAP(/* Fn Layer */
ESC, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, MINS, EQL, BSPC,/*14X*/
TAB, Q, W, E, R, T, Y,FN11, FN5,FN12, P, FN8, FN9, FN30,/*14X*/
LCTL,A,FN13, D, F,FN14, H, J, K, L,FN27, FN7, ENT, /*13X*/
LSHIFT, Z, X,FN15, V, B, N, M, VOLD,VOLU, MUTE,MPLY,TRNS,/*13X*/
LALT,LGUI, SPC, FN2, LEFT, DOWN, RGHT /*7X*/
),
KEYMAP(/* CODE Layer */
ESC, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, FN20, FN21, DEL,/*14X*/
TAB, Q, W, E, R, T, Y,FN11, FN5, FN4, FN22, FN16, FN17,FN19,/*14X*/
LCTL,A,FN13, FN1, F,FN14, H, J, K, L,SCLN, FN7, FN24, /*13X*/
LSHIFT, Z, X,FN15, V, B, N, M, FN25,FN26, SLSH, UP, FN3,/*13X*/
LALT,LGUI, SPC, TRNS, LEFT, DOWN, RGHT /*7X*/
),
KEYMAP(/* Windows Toggle Layer */
ESC, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, MINS, EQL, BSPC,/*14X*/
TAB, Q, W, E, R, T, Y,FN11, FN5,FN12, P, FN8, FN9, FN30,/*14X*/
LCTL,A,FN13, D, F,FN14, H, J, K, L,SCLN, FN7, ENT, /*13X*/
LSHIFT, Z, X,FN15, V, B, N, M, FN25,FN26, SLSH, UP, FN10,/*13X*/
LALT,LGUI, SPC, FN2, LEFT, DOWN, RGHT /*7X*/
),
};
/*
* Macro definition
*/
enum macro_id {
MAXIMIZE,
TR_U,TR_I,TR_O,TR_S,TR_G,TR_C,TR_i,
SHIFT_ESC,
BACKTICK,
CO1,CC1,
V_PREV,V_NEXT,V_DIFF,V_CHANGED,
C_PREV,C_NEXT,
IDE_COLOR,IDE_SWITCH,IDE_COMMANDS,
CO2,CC2,
SEMICOLON,
WINDOWS_MODE,
CHROME_INSPECT,
DELAY_TEST
};
void my_delay(times)
{
int i;
for(i=0;i<times*10;i++)
{
_delay_us(100);
}
}
const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt)
{
switch (id) {
case V_PREV:
return (record->event.pressed?MACRO(D(LCTRL),D(LSHIFT),T(PGUP),U(LSHIFT),U(LCTRL),END):MACRO(END));
case V_NEXT:
return (record->event.pressed?MACRO(D(LCTRL),D(LSHIFT),T(PGDN),U(LSHIFT),U(LCTRL),END):MACRO(END));
case V_DIFF:
return (record->event.pressed?MACRO(D(LCTRL),D(LALT),T(D),U(LALT),U(LCTRL),END):MACRO(END));
case V_CHANGED:
return (record->event.pressed?MACRO(D(LCTRL),D(LGUI),T(U),U(LGUI),U(LCTRL),END):MACRO(END));
case C_PREV:
return (record->event.pressed?MACRO(D(LGUI),T(PGDN),U(LGUI),END):MACRO(END));
case C_NEXT:
return (record->event.pressed?MACRO(D(LGUI),T(PGUP),U(LGUI),END):MACRO(END));
case IDE_COLOR:
return (record->event.pressed?MACRO(D(LGUI),D(LSHIFT),T(C),U(LSHIFT),U(LGUI),END):MACRO(END));
case IDE_SWITCH:
return (record->event.pressed?MACRO(D(LCTRL),D(LGUI),T(P),U(LGUI),U(LCTRL),END):MACRO(END));
case IDE_COMMANDS:
return (record->event.pressed?MACRO(D(LGUI),D(LSHIFT),T(P),U(LSHIFT),U(LGUI),END):MACRO(END));
case SEMICOLON:
return (record->event.pressed?MACRO(D(LSHIFT),T(SCLN),U(LSHIFT),END):MACRO(END));
case CHROME_INSPECT:
return (record->event.pressed?MACRO(D(LALT),D(LGUI),T(J),U(LGUI),U(LALT),END):MACRO(END));
case DELAY_TEST:
if (record->event.pressed) {
register_code(KC_D);
unregister_code(KC_D);
wait_ms(200);
register_code(KC_E);
unregister_code(KC_E);
wait_ms(200);
register_code(KC_L);
unregister_code(KC_L);
wait_ms(200);
register_code(KC_A);
unregister_code(KC_A);
wait_ms(200);
register_code(KC_Y);
unregister_code(KC_Y);
}
break;
case MAXIMIZE:
if (record->event.pressed) {
/*U"LGui"+U"LCtrl"+U"LAlt"+U"LShift"+U"O"*/
register_code(KC_LGUI);
register_code(KC_LCTRL);
register_code(KC_LALT);
register_code(KC_LSHIFT);
register_code(KC_O);
wait_ms(40);
register_code(KC_SPACE);
unregister_code(KC_SPACE);
register_code(KC_SPACE);
unregister_code(KC_SPACE);
register_code(KC_ESC);
unregister_code(KC_ESC);
register_code(KC_ESC);
unregister_code(KC_ESC);
unregister_code(KC_O);
unregister_code(KC_LSHIFT);
unregister_code(KC_LALT);
unregister_code(KC_LCTRL);
unregister_code(KC_LGUI);
}
break;
}
return MACRO_NONE;
}
void action_function(keyrecord_t *record, uint8_t id, uint8_t opt)
{
static bool TR_U_mode = false,TR_I_mode = false,TR_i_mode = false,TR_O_mode = false,TR_S_mode = false,TR_G_mode = false,TR_C_mode = false,SE_mode=false,BACKTICK_mode=false,CO1_mode=false,CC1_mode=false;
static bool windows_mode=false;
switch (id) {
case WINDOWS_MODE:
if(windows_mode) layer_off(4),windows_mode=false;
else layer_on(4),windows_mode=true;
/*led_set(0);*/
break;
case TR_U:
if (record->event.pressed) {
if (keyboard_report->mods & MOD_BIT(KC_LALT)) {
TR_U_mode = true;
unregister_code(KC_LALT);
register_code(KC_F13);
unregister_code(KC_F13);
my_delay(3);
register_code(KC_RBRC);unregister_code(KC_RBRC);
register_code(KC_F13);
unregister_code(KC_F13);
register_code(KC_LALT);
} else {
register_code(KC_U);
}
} else {
if (TR_U_mode) {
TR_U_mode = false;
} else {
unregister_code(KC_U);
}
}
break;
case TR_I:
if (record->event.pressed) {
if (keyboard_report->mods & MOD_BIT(KC_LALT)) {
TR_I_mode = true;
unregister_code(KC_LALT);
register_code(KC_F13);
unregister_code(KC_F13);
_delay_ms(1);
register_code(KC_I);unregister_code(KC_I);
register_code(KC_F13);
unregister_code(KC_F13);
register_code(KC_LALT);
} else {
register_code(KC_I);
}
} else {
if (TR_I_mode) {
TR_I_mode = false;
} else {
unregister_code(KC_I);
}
}
break;
case TR_i:
if (record->event.pressed) {
if (keyboard_report->mods & MOD_BIT(KC_LALT)) {
TR_i_mode = true;
unregister_code(KC_LALT);
register_code(KC_F13);
unregister_code(KC_F13);
_delay_ms(1);
register_code(KC_LSHIFT);
register_code(KC_QUOT);unregister_code(KC_QUOT);
unregister_code(KC_LSHIFT);
register_code(KC_F13);
unregister_code(KC_F13);
register_code(KC_LALT);
} else {
register_code(KC_BSLS);
}
} else {
if (TR_i_mode) {
TR_i_mode = false;
} else {
unregister_code(KC_BSLS);
}
}
break;
case TR_O:
if (record->event.pressed) {
if (keyboard_report->mods & MOD_BIT(KC_LALT)) {
TR_O_mode = true;
unregister_code(KC_LALT);
register_code(KC_F13);
unregister_code(KC_F13);
_delay_ms(1);
register_code(KC_COMM);unregister_code(KC_COMM);
register_code(KC_F13);
unregister_code(KC_F13);
register_code(KC_LALT);
} else {
register_code(KC_O);
}
} else {
if (TR_O_mode) {
TR_O_mode = false;
} else {
unregister_code(KC_O);
}
}
break;
case TR_S:
if (record->event.pressed) {
if (keyboard_report->mods & MOD_BIT(KC_LALT)) {
TR_S_mode = true;
unregister_code(KC_LALT);
register_code(KC_F13);
unregister_code(KC_F13);
_delay_ms(1);
register_code(KC_SCLN);unregister_code(KC_SCLN);
register_code(KC_F13);
unregister_code(KC_F13);
register_code(KC_LALT);
} else {
register_code(KC_S);
}
} else {
if (TR_S_mode) {
TR_S_mode = false;
} else {
unregister_code(KC_S);
}
}
break;
case TR_G:
if (record->event.pressed) {
if (keyboard_report->mods & MOD_BIT(KC_LALT)) {
TR_G_mode = true;
unregister_code(KC_LALT);
register_code(KC_F13);
unregister_code(KC_F13);
_delay_ms(1);
register_code(KC_LBRC);unregister_code(KC_LBRC);
register_code(KC_F13);
unregister_code(KC_F13);
register_code(KC_LALT);
} else {
register_code(KC_G);
}
} else {
if (TR_G_mode) {
TR_G_mode = false;
} else {
unregister_code(KC_G);
}
}
break;
case TR_C:
if (record->event.pressed) {
if (keyboard_report->mods & MOD_BIT(KC_LALT)) {
TR_C_mode = true;
unregister_code(KC_LALT);
register_code(KC_F13);
unregister_code(KC_F13);
_delay_ms(1);
register_code(KC_DOT);unregister_code(KC_DOT);
register_code(KC_F13);
unregister_code(KC_F13);
register_code(KC_LALT);
} else {
register_code(KC_C);
}
} else {
if (TR_C_mode) {
TR_C_mode = false;
} else {
unregister_code(KC_C);
}
}
break;
case BACKTICK:
if (record->event.pressed) {
if (keyboard_report->mods & MOD_BIT(KC_LALT)) {
BACKTICK_mode = true;
unregister_code(KC_LALT);
register_code(KC_GRV);
unregister_code(KC_GRV);
register_code(KC_LALT);
} else {
register_code(KC_QUOT);
}
} else {
if (BACKTICK_mode) {
BACKTICK_mode = false;
} else {
unregister_code(KC_QUOT);
}
}
break;
case CO1:
if (record->event.pressed) {
if (keyboard_report->mods & MOD_BIT(KC_LALT)) {
CO1_mode = true;
unregister_code(KC_LALT);
register_code(KC_SLSH); unregister_code(KC_SLSH);
register_code(KC_LSHIFT); register_code(KC_8); unregister_code(KC_8); unregister_code(KC_LSHIFT);
register_code(KC_LALT);
} else {
register_code(KC_LBRC);
}
} else {
if (CO1_mode) {
CO1_mode = false;
} else {
unregister_code(KC_LBRC);
}
}
break;
case CC1:
if (record->event.pressed) {
if (keyboard_report->mods & MOD_BIT(KC_LALT)) {
CC1_mode = true;
unregister_code(KC_LALT);
register_code(KC_LSHIFT); register_code(KC_8); unregister_code(KC_8); unregister_code(KC_LSHIFT);
register_code(KC_SLSH); unregister_code(KC_SLSH);
register_code(KC_LALT);
} else {
register_code(KC_RBRC);
}
} else {
if (CC1_mode) {
CC1_mode = false;
} else {
unregister_code(KC_RBRC);
}
}
break;
case CO2:
if (record->event.pressed) {
if (keyboard_report->mods & MOD_BIT(KC_LALT)) {
CO1_mode = true;
unregister_code(KC_LALT);
register_code(KC_LSHIFT); register_code(KC_COMM); unregister_code(KC_COMM); register_code(KC_1); unregister_code(KC_1); unregister_code(KC_LSHIFT);
register_code(KC_MINS); unregister_code(KC_MINS);
register_code(KC_MINS); unregister_code(KC_MINS);
register_code(KC_LALT);
} else {
register_code(KC_COMM);
}
} else {
if (CO1_mode) {
CO1_mode = false;
} else {
unregister_code(KC_COMM);
}
}
break;
case CC2:
if (record->event.pressed) {
if (keyboard_report->mods & MOD_BIT(KC_LALT)) {
CO1_mode = true;
unregister_code(KC_LALT);
register_code(KC_MINS); unregister_code(KC_MINS);
register_code(KC_MINS); unregister_code(KC_MINS);
register_code(KC_LSHIFT); register_code(KC_DOT); unregister_code(KC_DOT); unregister_code(KC_LSHIFT);
register_code(KC_LALT);
} else {
register_code(KC_DOT);
}
} else {
if (CO1_mode) {
CO1_mode = false;
} else {
unregister_code(KC_DOT);
}
}
break;
case SHIFT_ESC:
if (record->event.pressed) {
if (keyboard_report->mods & MOD_BIT(KC_LSHIFT)) {
SE_mode = true;
register_code(KC_GRV);
unregister_code(KC_GRV);
} else {
register_code(KC_ESC);
}
} else {
if (SE_mode) {
SE_mode = false;
} else {
unregister_code(KC_ESC);
}
}
break;
}
}
/*
* Fn action definition
*/
const action_t fn_actions[] PROGMEM = {\
[0] = ACTION_DEFAULT_LAYER_SET(0), // Default layer(not used)
[1] = ACTION_MACRO(DELAY_TEST), // HHKB layer(toggle with 5 taps)
[2] = ACTION_LAYER_MOMENTARY(2),
[3] = ACTION_MODS_ONESHOT(MOD_LSFT), // Oneshot Shift
[4] = ACTION_MACRO(MAXIMIZE), // Maximize window
[5] = ACTION_FUNCTION(TR_I),
[6] = ACTION_FUNCTION(SHIFT_ESC),
[7] = ACTION_FUNCTION(BACKTICK),
[8] = ACTION_FUNCTION(CO1),
[9] = ACTION_FUNCTION(CC1),
[10]= ACTION_LAYER_MOMENTARY(1), // Right-Fn
[11] = ACTION_FUNCTION(TR_U),
[12] = ACTION_FUNCTION(TR_O),
[13] = ACTION_FUNCTION(TR_S),
[14] = ACTION_FUNCTION(TR_G),
[15] = ACTION_FUNCTION(TR_C),
[16] = ACTION_MACRO(V_PREV), /* [ */
[17] = ACTION_MACRO(V_NEXT), /* ] */
[18] = ACTION_MACRO(V_DIFF), /* D */
[19] = ACTION_MACRO(V_CHANGED), /* \ */
[20] = ACTION_MACRO(C_PREV), /* - */
[21] = ACTION_MACRO(C_NEXT), /* = */
[22] = ACTION_MACRO(IDE_SWITCH), /* P */
[23] = ACTION_MACRO(IDE_COLOR), /* C */
[24] = ACTION_MACRO(IDE_COMMANDS), /* Enter */
[25] = ACTION_FUNCTION(CO2), /* <!-- */
[26] = ACTION_FUNCTION(CC2), /* --> */
[27] = ACTION_MACRO(SEMICOLON), /* : */
[28] = ACTION_FUNCTION(WINDOWS_MODE), /* : */
[29] = ACTION_LAYER_TOGGLE(3),
[30] = ACTION_FUNCTION(TR_i),
[31] = ACTION_MACRO(CHROME_INSPECT),
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment