bool KGlobalAccelImpl::grabKey( int keyQt, bool grab ) { if (grab) { kDebug() << "Grabbing key " << keyQt; QList<uint> keyCodes; uint mod; KKeyServer::keyQtToCodeMac( keyQt, keyCodes ); KKeyServer::keyQtToModMac( keyQt, mod ); kDebug() << "keyQt: " << keyQt << " mod: " << mod; foreach (uint keyCode, keyCodes) { kDebug() << " keyCode: " << keyCode; } EventHotKeyID ehkid; ehkid.signature = 'Kgai'; ehkid.id = keyQt; QList<EventHotKeyRef> hotkeys; foreach (uint keyCode, keyCodes) { EventHotKeyRef ref; if (RegisterEventHotKey(keyCode, mod, ehkid, m_eventTarget, 0, &ref) != noErr) { kWarning(125) << "RegisterEventHotKey failed!"; } hotkeys.append(ref); } refs->insert(keyQt, hotkeys); } else {
UInt32 COSXScreen::registerHotKey(KeyID key, KeyModifierMask mask) { // get mac virtual key and modifier mask matching synergy key and mask UInt32 macKey, macMask; if (!m_keyState->mapSynergyHotKeyToMac(key, mask, macKey, macMask)) { LOG((CLOG_DEBUG "could not map hotkey id=%04x mask=%04x", key, mask)); return 0; } // choose hotkey id UInt32 id; if (!m_oldHotKeyIDs.empty()) { id = m_oldHotKeyIDs.back(); m_oldHotKeyIDs.pop_back(); } else { id = m_hotKeys.size() + 1; } // if this hot key has modifiers only then we'll handle it specially EventHotKeyRef ref = NULL; bool okay; if (key == kKeyNone) { if (m_modifierHotKeys.count(mask) > 0) { // already registered okay = false; } else { m_modifierHotKeys[mask] = id; okay = true; } } else { EventHotKeyID hkid = { 'SNRG', (UInt32)id }; OSStatus status = RegisterEventHotKey(macKey, macMask, hkid, GetApplicationEventTarget(), 0, &ref); okay = (status == noErr); m_hotKeyToIDMap[CHotKeyItem(macKey, macMask)] = id; } if (!okay) { m_oldHotKeyIDs.push_back(id); m_hotKeyToIDMap.erase(CHotKeyItem(macKey, macMask)); LOG((CLOG_WARN "failed to register hotkey %s (id=%04x mask=%04x)", CKeyMap::formatKey(key, mask).c_str(), key, mask)); return 0; } m_hotKeys.insert(std::make_pair(id, CHotKeyItem(ref, macKey, macMask))); LOG((CLOG_DEBUG "registered hotkey %s (id=%04x mask=%04x) as id=%d", CKeyMap::formatKey(key, mask).c_str(), key, mask, id)); return id; }
bool QxtGlobalShortcutPrivate::registerShortcut(quint32 nativeKey, quint32 nativeMods) { if (!qxt_mac_handler_installed) { EventTypeSpec t; t.eventClass = kEventClassKeyboard; t.eventKind = kEventHotKeyPressed; InstallApplicationEventHandler(&qxt_mac_handle_hot_key, 1, &t, NULL, NULL); } EventHotKeyID keyID; keyID.signature = 'cute'; keyID.id = ++hotKeySerial; EventHotKeyRef ref = 0; bool rv = !RegisterEventHotKey(nativeKey, nativeMods, keyID, GetApplicationEventTarget(), 0, &ref); if (rv) { keyIDs.insert(Identifier(nativeMods, nativeKey), keyID.id); keyRefs.insert(keyID.id, ref); } return rv; }