bool ShortcutManager::registerShortcut(QKeySequence shortcut) { Qt::KeyboardModifiers allMods = Qt::ShiftModifier | Qt::ControlModifier | Qt::AltModifier | Qt::MetaModifier; Qt::Key key = shortcut.isEmpty() ? Qt::Key(0) : Qt::Key((shortcut[0] ^ allMods) & shortcut[0]); Qt::KeyboardModifiers mods = shortcut.isEmpty() ? Qt::KeyboardModifiers(0) : Qt::KeyboardModifiers(shortcut[0] & allMods); this->nativeKey = nativeKeycode(key); this->nativeMods = nativeModifiers(mods); return RegisterHotKey(0, nativeMods ^ nativeKey, nativeMods, nativeKey); }
bool QtGlobalShortcutPrivate::unsetShortcut() { const quint32 nativeKey = nativeKeycode(key); const quint32 nativeMods = nativeModifiers(mods); const bool res = unregisterShortcut(nativeKey, nativeMods); shortcuts.remove(qMakePair(nativeKey, nativeMods)); if (!res) qWarning() << "QtGlobalShortcut failed to unregister:" << QKeySequence(key + mods).toString(); key = Qt::Key(0); mods = Qt::KeyboardModifiers(0); return res; }
bool MyGlobalShortCut::registerHotKey() { Qt::KeyboardModifiers allMods = Qt::ShiftModifier | Qt::ControlModifier | Qt::AltModifier | Qt::MetaModifier; key = (m_key.isEmpty() ? Qt::Key(0) : Qt::Key((m_key[0] ^ allMods) & m_key[0])); mods = m_key.isEmpty() ? Qt::KeyboardModifiers(0) : Qt::KeyboardModifiers(m_key[0] & allMods); const quint32 nativeKey = nativeKeycode(key); const quint32 nativeMods = nativeModifiers(mods); shortcuts.insert(qMakePair(nativeKey, nativeMods),this); return RegisterHotKey(0, nativeMods ^ nativeKey, nativeMods, nativeKey); }
bool QtGlobalShortcutPrivate::setShortcut(const QKeySequence& shortcut) { Qt::KeyboardModifiers allMods = Qt::ShiftModifier | Qt::ControlModifier | Qt::AltModifier | Qt::MetaModifier; key = shortcut.isEmpty() ? Qt::Key(0) : Qt::Key((shortcut[0] ^ allMods) & shortcut[0]); mods = shortcut.isEmpty() ? Qt::KeyboardModifiers(0) : Qt::KeyboardModifiers(shortcut[0] & allMods); const quint32 nativeKey = nativeKeycode(key); const quint32 nativeMods = nativeModifiers(mods); const bool res = registerShortcut(nativeKey, nativeMods); shortcuts.insert(qMakePair(nativeKey, nativeMods), &qxt_p()); if (!res) qWarning() << "QtGlobalShortcut failed to register:" << QKeySequence(key + mods).toString(); return res; }
bool QxtGlobalShortcutPrivate::unsetShortcut() { bool res = false; const quint32 nativeKey = nativeKeycode(key); const quint32 nativeMods = nativeModifiers(mods); if (shortcuts.value(qMakePair(nativeKey, nativeMods)) == &qxt_p()) res = unregisterShortcut(nativeKey, nativeMods); if (res) shortcuts.remove(qMakePair(nativeKey, nativeMods)); else qWarning() << "QxtGlobalShortcut failed to unregister:" << QKeySequence(key + mods).toString(); key = Qt::Key(0); mods = Qt::KeyboardModifiers(0); return res; }
bool QxtGlobalShortcutPrivate::setShortcut(const QKeySequence &shortcut) { Q_Q(QxtGlobalShortcut); Qt::KeyboardModifiers allMods = Qt::ShiftModifier | Qt::ControlModifier | Qt::AltModifier | Qt::MetaModifier; key = shortcut.isEmpty() ? Qt::Key(0) : Qt::Key((shortcut[0] ^ allMods) & shortcut[0]); mods = shortcut.isEmpty() ? Qt::KeyboardModifiers(Qt::NoModifier) : Qt::KeyboardModifiers(shortcut[0] & allMods); const quint32 nativeKey = nativeKeycode(key); const quint32 nativeMods = nativeModifiers(mods); const bool res = registerShortcut(nativeKey, nativeMods); if (res) shortcuts.insert({nativeKey, nativeMods}, q); else qWarning("QxtGlobalShortcut failed to register: %s", qPrintable(QKeySequence(key + mods).toString())); return res; }
bool QxtGlobalShortcutPrivate::unsetShortcut() { Q_Q(QxtGlobalShortcut); bool res = false; const quint32 nativeKey = nativeKeycode(key); const quint32 nativeMods = nativeModifiers(mods); if (shortcuts.value({nativeKey, nativeMods}) == q) res = unregisterShortcut(nativeKey, nativeMods); if (res) shortcuts.remove({nativeKey, nativeMods}); else qWarning("QxtGlobalShortcut failed to unregister: %s", qPrintable(QKeySequence(key + mods).toString())); key = Qt::Key(0); mods = Qt::KeyboardModifiers(Qt::NoModifier); return res; }
void dUpload::keyPressEvent( QKeyEvent *event ) { #if defined( Q_WS_WIN ) || defined( Q_WS_MAC ) quint32 key = event->nativeVirtualKey(); #elif defined( Q_WS_X11 ) quint32 key = event->nativeScanCode(); #endif if ( key == nativeKeycode( 'T' ) || key == nativeKeycode( 'P' ) ) { if ( !m_filename.isEmpty() ) new dPreview( m_filename ); } else if ( key == nativeKeycode( 'H' ) ) { hide(); } else if ( key == nativeKeycode( 'B' ) ) { sendFromClipboard(); } else if ( key == nativeKeycode( 'N' ) ) { sendFromClipboard( 1 ); } else if ( key == nativeKeycode( 'W' ) ) { show( windowFlags() ^ Qt::WindowStaysOnTopHint ); } else if ( key == nativeKeycode( 'R' ) ) { dExternal::instance( this )->userRegister(); } else if ( key == nativeKeycode( 'A' ) ) { dExternal::instance( this )->userAuth(); } else if ( key == nativeKeycode( 'D' ) ) { setPasskey(); setUserlogin(); notify( "You're logged out" ); } else if ( key == nativeKeycode( 'L' ) ) { showLast(); } else if ( key == nativeKeycode( 'S' ) ) { dSettings::instance()->show(); } }
bool MyGlobalShortCut::unregisterHotKey() { return UnregisterHotKey(0, (quint32)nativeModifiers(mods) ^ (quint32)nativeKeycode(key)); }
void NativeCommandEmitter::sendNativeKey(Qt::Key key, bool down) { quint32 keyCode = nativeKeycode(key); XTestFakeKeyEvent( display, keyCode, down, 0); }