简体   繁体   中英

How to convert QKeyEvent::nativeModifiers() to UINT fsModifiers (for winapi RegisterHotKey)

I have:

QKeyEvent* event; // I pressed "SHIFT"
modifiers = event->nativeModifiers(); // This is 513 value
RegisterHotKey(..., ..., modifiers, ...); // FAILED because 513 is bad modifier. 
//Right code of "SHIFT" is MOD_SHIFT = 0x0004

How to get the right native Windows modifier from QKeyEvent for winapi RegisterHotKey function?

Details:

Qt 5.4; QKeyEvent ; RegisterHotKey

You can do it similarly to how Qxt library converts the modifiers:

modifiers = event->nativeModifiers();

quint32 native = 0;
if (modifiers & Qt::ShiftModifier)
    native |= MOD_SHIFT;
if (modifiers & Qt::ControlModifier)
    native |= MOD_CONTROL;
if (modifiers & Qt::AltModifier)
    native |= MOD_ALT;
if (modifiers & Qt::MetaModifier)
    native |= MOD_WIN;

RegisterHotKey(..., ..., native, ...);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM