RustAudio / baseview

low-level window system interface for audio plugin UIs
Apache License 2.0
266 stars 57 forks source link

macOS: keyboard event handling #53

Closed greatest-ape closed 3 years ago

greatest-ape commented 3 years ago

We should do this similarily to how it is done in druid.

Cocoa documentation is here. xcb info about keycodes here, iced keyboard event, druid implementation, useful crate

Snippet to extract string from key event:

let characters = unsafe {
    let ns_string = NSEvent::characters(event);

    let start = NSString::UTF8String(ns_string);
    let len = NSString::len(ns_string);

    let slice = ::std::slice::from_raw_parts(
        start as *const u8,
        len
    );

    ::std::str::from_utf8_unchecked(slice)
};