summaryrefslogtreecommitdiffstats
path: root/cmd-send-keys.c
diff options
context:
space:
mode:
Diffstat (limited to 'cmd-send-keys.c')
-rw-r--r--cmd-send-keys.c40
1 files changed, 28 insertions, 12 deletions
diff --git a/cmd-send-keys.c b/cmd-send-keys.c
index d6a9543..ac99a6f 100644
--- a/cmd-send-keys.c
+++ b/cmd-send-keys.c
@@ -33,13 +33,13 @@ const struct cmd_entry cmd_send_keys_entry = {
.name = "send-keys",
.alias = "send",
- .args = { "FHlMN:Rt:X", 0, -1, NULL },
- .usage = "[-FHlMRX] [-N repeat-count] " CMD_TARGET_PANE_USAGE
- " key ...",
+ .args = { "c:FHKlMN:Rt:X", 0, -1, NULL },
+ .usage = "[-FHKlMRX] [-c target-client] [-N repeat-count] "
+ CMD_TARGET_PANE_USAGE " key ...",
.target = { 't', CMD_FIND_PANE, 0 },
- .flags = CMD_AFTERHOOK,
+ .flags = CMD_AFTERHOOK|CMD_CLIENT_CFLAG|CMD_CLIENT_CANFAIL,
.exec = cmd_send_keys_exec
};
@@ -58,7 +58,7 @@ const struct cmd_entry cmd_send_prefix_entry = {
static struct cmdq_item *
cmd_send_keys_inject_key(struct cmdq_item *item, struct cmdq_item *after,
- key_code key)
+ struct args *args, key_code key)
{
struct cmd_find_state *target = cmdq_get_target(item);
struct client *tc = cmdq_get_target_client(item);
@@ -66,8 +66,20 @@ cmd_send_keys_inject_key(struct cmdq_item *item, struct cmdq_item *after,
struct winlink *wl = target->wl;
struct window_pane *wp = target->wp;
struct window_mode_entry *wme;
- struct key_table *table;
+ struct key_table *table = NULL;
struct key_binding *bd;
+ struct key_event *event;
+
+ if (args_has(args, 'K')) {
+ if (tc == NULL)
+ return (item);
+ event = xmalloc(sizeof *event);
+ event->key = key|KEYC_SENT;
+ memset(&event->m, 0, sizeof event->m);
+ if (server_client_handle_key(tc, event) == 0)
+ free(event);
+ return (item);
+ }
wme = TAILQ_FIRST(&wp->modes);
if (wme == NULL || wme->mode->key_table == NULL) {
@@ -102,14 +114,16 @@ cmd_send_keys_inject_string(struct cmdq_item *item, struct cmdq_item *after,
n = strtol(s, &endptr, 16);
if (*s =='\0' || n < 0 || n > 0xff || *endptr != '\0')
return (item);
- return (cmd_send_keys_inject_key(item, after, KEYC_LITERAL|n));
+ return (cmd_send_keys_inject_key(item, after, args,
+ KEYC_LITERAL|n));
}
literal = args_has(args, 'l');
if (!literal) {
key = key_string_lookup_string(s);
if (key != KEYC_NONE && key != KEYC_UNKNOWN) {
- after = cmd_send_keys_inject_key(item, after, key);
+ after = cmd_send_keys_inject_key(item, after, args,
+ key);
if (after != NULL)
return (after);
}
@@ -125,7 +139,8 @@ cmd_send_keys_inject_string(struct cmdq_item *item, struct cmdq_item *after,
continue;
key = uc;
}
- after = cmd_send_keys_inject_key(item, after, key);
+ after = cmd_send_keys_inject_key(item, after, args,
+ key);
}
free(ud);
}
@@ -151,7 +166,8 @@ cmd_send_keys_exec(struct cmd *self, struct cmdq_item *item)
char *cause = NULL;
if (args_has(args, 'N')) {
- np = args_strtonum(args, 'N', 1, UINT_MAX, &cause);
+ np = args_strtonum_and_expand(args, 'N', 1, UINT_MAX, item,
+ &cause);
if (cause != NULL) {
cmdq_error(item, "repeat count %s", cause);
free(cause);
@@ -192,7 +208,7 @@ cmd_send_keys_exec(struct cmd *self, struct cmdq_item *item)
key = options_get_number(s->options, "prefix2");
else
key = options_get_number(s->options, "prefix");
- cmd_send_keys_inject_key(item, item, key);
+ cmd_send_keys_inject_key(item, item, args, key);
return (CMD_RETURN_NORMAL);
}
@@ -206,7 +222,7 @@ cmd_send_keys_exec(struct cmd *self, struct cmdq_item *item)
if (args_has(args, 'N') || args_has(args, 'R'))
return (CMD_RETURN_NORMAL);
for (; np != 0; np--)
- cmd_send_keys_inject_key(item, NULL, event->key);
+ cmd_send_keys_inject_key(item, NULL, args, event->key);
return (CMD_RETURN_NORMAL);
}