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
2 changes: 1 addition & 1 deletion makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ all: clean $(BINS)
install: BUILD_FLAGS=-std=c99 -O3
install: clean $(BINS)

profile: BUILD_FLAGS=-std=c99 -Wall -g -O0 -DSKHD_PROFILE
profile: BUILD_FLAGS=-std=c99 -Wall -g -O0 -DSKHD_PROFILE -fsanitize=address,undefined -fno-omit-frame-pointer
profile: clean $(BINS)

fast_profile: BUILD_FLAGS=-std=c99 -O3 -DSKHD_PROFILE
Expand Down
7 changes: 6 additions & 1 deletion src/skhd.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,13 @@ internal bool
parse_arguments(int argc, char **argv)
{
int option;
const char *short_option = "Vvc:k:t:";
const char *short_option = "Vvc:k:a:t:";
struct option long_option[] = {
{ "verbose", no_argument, NULL, 'V' },
{ "version", no_argument, NULL, 'v' },
{ "config", required_argument, NULL, 'c' },
{ "key", required_argument, NULL, 'k' },
{ "ascii", required_argument, NULL, 'a' },
{ "text", required_argument, NULL, 't' },
{ NULL, 0, NULL, 0 }
};
Expand All @@ -154,6 +155,10 @@ parse_arguments(int argc, char **argv)
synthesize_key(optarg);
return true;
} break;
case 'a': {
synthesize_ascii(optarg);
return true;
} break;
case 't': {
synthesize_text(optarg);
return true;
Expand Down
26 changes: 26 additions & 0 deletions src/synthesize.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,32 @@ void synthesize_key(char *key_string)
synthesize_modifiers(hotkey, false);
}

void synthesize_ascii(char *text){
size_t n = strlen(text);
for (size_t i = 0; i < n; i++){
// take 1 char from ascii text
char c[2];
memcpy(c, &text[i], 1);
c[1] = '\0';

if (!initialize_keycode_map()) continue;
struct parser parser;

parser_init_text(&parser, c);
struct hotkey *hotkey = parse_keypress(&parser);
if (!hotkey) continue;
CGSetLocalEventsSuppressionInterval(0.0f);
CGEnableEventStateCombining(false);

create_and_post_keyevent(hotkey->key, true);
create_and_post_keyevent(hotkey->key, false);
usleep(300);
free(hotkey);
}
close(1);
close(2);
}

void synthesize_text(char *text)
{
CFStringRef text_ref = CFStringCreateWithCString(NULL, text, kCFStringEncodingUTF8);
Expand Down