Skip to main content

Crate typechar

Crate typechar 

Source
Expand description

Type any Unicode string on macOS, regardless of keyboard layout.

The string is posted directly as a keyboard event via CoreGraphics (CGEventKeyboardSetUnicodeString), so the active keyboard layout is never consulted — characters that no key combination can produce still arrive at the frontmost app.

if !typechar::has_permission() {
    typechar::request_permission(); // prompts the user via System Settings
}
typechar::type_string("¯\\_(ツ)_/¯")?;

The calling process needs macOS Accessibility permission (System Settings → Privacy & Security → Accessibility); without it type_string returns TypeError::PermissionDenied instead of silently typing nothing.

Enums§

Action
What the process should do, decided from argv.
TypeError
Why typing failed.

Functions§

decode_codepoint
Decode a hex codepoint like “20ac” or “U+20AC” into a char.
has_permission
Whether the calling process may post keyboard events.
parse_args
Parse argv (excluding argv[0]) into an Action.
request_permission
Ask macOS to prompt the user to grant this process Accessibility permission (opens System Settings). Returns whether permission is held.
type_string
Type text into the frontmost application, bypassing the keyboard layout.
utf16_chunks
Split text into UTF-16 chunks of at most max_units code units, never splitting a surrogate pair across chunks.