1
0

Fix 'Shift Parentheses' example

This commit is contained in:
tmk 2014-04-24 11:27:33 +09:00
parent 3c5add5f80
commit 00e9a342df

View File

@ -25,7 +25,7 @@ const uint8_t keymaps[][MATRIX_ROWS][MATRIX_COLS] PROGMEM = {
KEYMAP(ESC, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, MINS,EQL, BSLS,GRV, \ KEYMAP(ESC, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, MINS,EQL, BSLS,GRV, \
TAB, Q, W, E, R, T, Y, U, I, O, P, LBRC,RBRC,BSPC, \ TAB, Q, W, E, R, T, Y, U, I, O, P, LBRC,RBRC,BSPC, \
LCTL,A, S, D, F, G, H, J, K, L, FN3, QUOT,FN4, \ LCTL,A, S, D, F, G, H, J, K, L, FN3, QUOT,FN4, \
FN5, Z, X, C, V, B, N, M, COMM,DOT, FN2, RSFT,FN1, \ FN11,Z, X, C, V, B, N, M, COMM,DOT, FN2, RSFT,FN1, \
LGUI,LALT, FN6, RALT,RGUI), LGUI,LALT, FN6, RALT,RGUI),
/* Layer 1: HHKB mode (HHKB Fn) /* Layer 1: HHKB mode (HHKB Fn)
@ -131,12 +131,9 @@ const uint8_t keymaps[][MATRIX_ROWS][MATRIX_COLS] PROGMEM = {
/* id for user defined functions */ /* id for user defined functions */
enum function_id { enum function_id {
LSHIFT_LPAREN, LSHIFT_LPAREN,
RSHIFT_RPAREN,
}; };
enum macro_id { enum macro_id {
LSHIFT_PAREN,
RSHIFT_PAREN,
HELLO, HELLO,
VOLUP, VOLUP,
}; };
@ -163,10 +160,7 @@ const uint16_t fn_actions[] PROGMEM = {
// [8] = ACTION_LMOD_TAP_KEY(KC_LCTL, KC_BSPC), // LControl with tap Backspace // [8] = ACTION_LMOD_TAP_KEY(KC_LCTL, KC_BSPC), // LControl with tap Backspace
// [9] = ACTION_LMOD_TAP_KEY(KC_LCTL, KC_ESC), // LControl with tap Esc // [9] = ACTION_LMOD_TAP_KEY(KC_LCTL, KC_ESC), // LControl with tap Esc
[11] = ACTION_FUNCTION_TAP(LSHIFT_LPAREN), // Function: LShift with tap '(' [11] = ACTION_FUNCTION_TAP(LSHIFT_LPAREN), // Function: LShift with tap '('
[12] = ACTION_FUNCTION_TAP(RSHIFT_RPAREN), // Function: RShift with tap ')'
// [13] = ACTION_MACRO_TAP(LSHIFT_PAREN), // Macro: LShift with tap '('
// [14] = ACTION_MACRO_TAP(RSHIFT_PAREN), // Macro: RShift with tap ')'
// [15] = ACTION_MACRO(HELLO), // Macro: say hello // [15] = ACTION_MACRO(HELLO), // Macro: say hello
// [9] = ACTION_MACRO(VOLUP), // Macro: media key // [9] = ACTION_MACRO(VOLUP), // Macro: media key
}; };
@ -177,32 +171,13 @@ const uint16_t fn_actions[] PROGMEM = {
*/ */
const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt) const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt)
{ {
keyevent_t event = record->event;
tap_t tap = record->tap;
switch (id) { switch (id) {
case LSHIFT_PAREN:
if (tap.count > 0 && !tap.interrupted) {
return (event.pressed ?
MACRO( D(LSHIFT), D(9), U(9), U(LSHIFT), END ) : MACRO_NONE);
} else {
return (event.pressed ?
MACRO( D(LSHIFT), END ) : MACRO( U(LSHIFT), END ) );
}
case RSHIFT_PAREN:
if (tap.count > 0 && !tap.interrupted) {
return (event.pressed ?
MACRO( D(RSHIFT), D(0), U(0), U(RSHIFT), END ) : MACRO_NONE);
} else {
return (event.pressed ?
MACRO( D(RSHIFT), END ) : MACRO( U(RSHIFT), END ) );
}
case HELLO: case HELLO:
return (event.pressed ? return (record->event.pressed ?
MACRO( I(0), T(H), T(E), T(L), T(L), W(255), T(O), END ) : MACRO( I(0), T(H), T(E), T(L), T(L), W(255), T(O), END ) :
MACRO_NONE ); MACRO_NONE );
case VOLUP: case VOLUP:
return (event.pressed ? return (record->event.pressed ?
MACRO( D(VOLU), U(VOLU), END ) : MACRO( D(VOLU), U(VOLU), END ) :
MACRO_NONE ); MACRO_NONE );
} }
@ -216,48 +191,36 @@ const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt)
*/ */
void action_function(keyrecord_t *record, uint8_t id, uint8_t opt) void action_function(keyrecord_t *record, uint8_t id, uint8_t opt)
{ {
keyevent_t event = record->event; if (record->event.pressed) dprint("P"); else dprint("R");
tap_t tap = record->tap; dprintf("%d", record->tap.count);
if (record->tap.interrupted) dprint("i");
dprint("\n");
switch (id) { switch (id) {
case LSHIFT_LPAREN: case LSHIFT_LPAREN:
// LShft + tap '(' // Shift parentheses example: LShft + tap '('
// NOTE: cant use register_code to avoid conflicting with magic key bind // http://stevelosh.com/blog/2012/10/a-modern-space-cadet/#shift-parentheses
if (event.pressed) { // http://geekhack.org/index.php?topic=41989.msg1304899#msg1304899
if (tap.count == 0 || tap.interrupted) { if (record->event.pressed) {
//add_mods(MOD_BIT(KC_LSHIFT)); if (record->tap.count > 0 && !record->tap.interrupted) {
layer_on(1); if (record->tap.interrupted) {
dprint("tap interrupted\n");
register_mods(MOD_BIT(KC_LSHIFT));
}
} else { } else {
add_mods(MOD_BIT(KC_LSHIFT)); register_mods(MOD_BIT(KC_LSHIFT));
add_key(KC_9);
send_keyboard_report();
del_mods(MOD_BIT(KC_LSHIFT));
del_key(KC_9);
send_keyboard_report();
} }
} else { } else {
if (tap.count == 0 || tap.interrupted) { if (record->tap.count > 0 && !(record->tap.interrupted)) {
//del_mods(MOD_BIT(KC_LSHIFT)); add_weak_mods(MOD_BIT(KC_LSHIFT));
layer_off(1); send_keyboard_report();
} register_code(KC_9);
} unregister_code(KC_9);
break; del_weak_mods(MOD_BIT(KC_LSHIFT));
case RSHIFT_RPAREN: send_keyboard_report();
// RShift + tap ')' record->tap.count = 0; // ad hoc: cancel tap
if (event.pressed) {
if (tap.count == 0 || tap.interrupted) {
add_mods(MOD_BIT(KC_RSHIFT));
} else { } else {
add_mods(MOD_BIT(KC_RSHIFT)); unregister_mods(MOD_BIT(KC_LSHIFT));
add_key(KC_0);
send_keyboard_report();
del_mods(MOD_BIT(KC_RSHIFT));
del_key(KC_0);
send_keyboard_report();
}
} else {
if (tap.count == 0 || tap.interrupted) {
del_mods(MOD_BIT(KC_RSHIFT));
} }
} }
break; break;