Привязка к Медиа включает клавиатуры Apple под [закрытым] OSX 10.5

Сделайте это:

<div id="sampleDiv">aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa</div>

#sampleDiv{
   overflow-wrap: break-word;
}
5
задан tryx 27 June 2009 в 18:08
поделиться

2 ответа

После более обширного поиска в Google это http://www.rogueamoeba.com/utm/2007/09/29/ , похоже, решает проблему. Нет простого решения, но если вы разрабатываете настоящее приложение для Какао, это, по крайней мере, кажется возможным.

7
ответ дан 13 December 2019 в 19:33
поделиться

From my investigations, the operating system is trapping those key events before they are available to other processes. I created a CGEventTap, like so:

int main(int argc, char *argv[]) {
CFMachPortRef      eventTap;
CFRunLoopSourceRef runLoopSource;

eventTap = CGEventTapCreate(kCGHIDEventTap, kCGHeadInsertEventTap, kCGEventTapOptionListenOnly, kCGEventMaskForAllEvents, myCGEventCallback, NULL);

if (!eventTap) {
    NSLog(@"Couldn't create event tap!");
    exit(1);
}

runLoopSource = CFMachPortCreateRunLoopSource(kCFAllocatorDefault, eventTap, 0);

CFRunLoopAddSource(CFRunLoopGetCurrent(), runLoopSource, kCFRunLoopCommonModes);

CGEventTapEnable(eventTap, true);

CFRunLoopRun();

CFRelease(eventTap);
CFRelease(runLoopSource);

exit(0);

}

And then the actual event callback is this:

CGEventRef myCGEventCallback(CGEventTapProxy proxy, CGEventType type, CGEventRef event, void *refcon) {
    if (type == kCGEventKeyUp) {
        CGKeyCode keycode = CGEventGetIntegerValueField(event, kCGKeyboardEventKeycode);
        NSLog(@"%d", keycode);
    }

    return event;
}

What you see logged to the console is that you get normal log methods for function keys (if you're holding down the "fn" key as well), but when pressing the media keys, brightness, volume, or eject keys, nothing is getting logged.

So from this, it unfortunately appears that there's no way to capture a media key event. However, I would love to be proved wrong.

EDIT: I forgot to point out that for this to work it either needs to run as root, or you need to turn on access for assistive devices in the "Universal Access" pane of System Preferences.

4
ответ дан 13 December 2019 в 19:33
поделиться
Другие вопросы по тегам:

Похожие вопросы: