Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/keyd.scdoc
Original file line number Diff line number Diff line change
Expand Up @@ -694,6 +694,10 @@ A key may optionally be bound to an _action_ which accepts zero or more argument
*clearm(<macro>)*
Identical to *clear*, but executes the supplied macro before clearing layers.

*togglekey(<key>)*
Toggle whether the key is pressed. Effectively holds the key down until
togglekey is performed again.

## Key overloading

*overload(<layer>, <action>)*
Expand Down
9 changes: 9 additions & 0 deletions src/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,14 @@ static struct {
ARG_TIMEOUT,
ARG_SENSITIVITY,
ARG_DESCRIPTOR,
ARG_KEYCODE,
} args[MAX_DESCRIPTOR_ARGS];
} actions[] = {
{ "swap", NULL, OP_SWAP, { ARG_LAYER } },
{ "clear", NULL, OP_CLEAR, {} },
{ "oneshot", NULL, OP_ONESHOT, { ARG_LAYER } },
{ "toggle", NULL, OP_TOGGLE, { ARG_LAYER } },
{ "togglekey", NULL, OP_TOGGLEKEY, { ARG_KEYCODE } },

{ "clearm", NULL, OP_CLEARM, { ARG_MACRO } },
{ "swapm", NULL, OP_SWAPM, { ARG_LAYER, ARG_MACRO } },
Expand Down Expand Up @@ -753,6 +755,13 @@ static int parse_descriptor(char *s,
arg->idx = config->nr_macros;
config->nr_macros++;

break;
case ARG_KEYCODE:
arg->code = lookup_keycode(argstr);
if (arg->code == 0) {
err("%s is not a valid keycode", argstr);
return -1;
}
break;
default:
assert(0);
Expand Down
1 change: 1 addition & 0 deletions src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ enum op {
OP_OVERLOAD_IDLE_TIMEOUT,
OP_TOGGLE,
OP_TOGGLEM,
OP_TOGGLEKEY,

OP_MACRO,
OP_MACRO2,
Expand Down
11 changes: 11 additions & 0 deletions src/keyboard.c
Original file line number Diff line number Diff line change
Expand Up @@ -729,6 +729,17 @@ static long process_descriptor(struct keyboard *kbd, uint8_t code,
clear_oneshot(kbd);
}

break;
case OP_TOGGLEKEY:
new_code = d->args[0].code;

if (pressed) {
if (kbd->keystate[new_code]) {
send_key(kbd, new_code, 0);
} else {
send_key(kbd, new_code, 1);
}
}
break;
case OP_TIMEOUT:
struct pending_timeout *pt = &kbd->pending_timeout;
Expand Down
1 change: 1 addition & 0 deletions t/test.conf
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ p = layerm(shift, macro(on))
1+2 = oneshot(test)
l = layer(test)
m = macro(C-h one)
n = togglekey(q)
c = oneshot(control)
s = layer(shift)
o = overloadt(control, a, 10)
Expand Down
11 changes: 11 additions & 0 deletions t/togglekey.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
n down
n up
a down
a up
n down
n up

q down
a down
a up
q up