How to get nativeVirtualKey for arrow keys [SOLVED]
-
@mrjj You mean this?
QKeyEvent(QEvent::KeyPress, Qt::Key_Up, Qt::NoModifier).nativeVirtualKey();
This is not works too - this statement returns 0.@mrjj said:
No its another function than native virtualkey.void keyPressEvent ( QKeyEvent* ke ) { int nativeCode = ke->nativeScanCode(); qDebug() << nativeCode; }
lists values for arrow keys. Not sure sure if it is the one you want.
For test I also tried nativeVirtualKey and it returns
37,38,39,40 for arrows which seems to be VK_LEFT etc.From this line I assume you try to use it as lookup call ?QKeyEvent(QEvent::KeyPress, Qt::Key_Up, Qt::NoModifier).nativeVirtualKey();
You are not catching a real key even but try into to convert from qt::key_up to sort of like VK_ARROWUP ?
I do not think this can work since the real event provides the sym key and here you just construct a fake one so this info is not there.
-
@mrjj said:
No its another function than native virtualkey.void keyPressEvent ( QKeyEvent* ke ) { int nativeCode = ke->nativeScanCode(); qDebug() << nativeCode; }
lists values for arrow keys. Not sure sure if it is the one you want.
For test I also tried nativeVirtualKey and it returns
37,38,39,40 for arrows which seems to be VK_LEFT etc.From this line I assume you try to use it as lookup call ?QKeyEvent(QEvent::KeyPress, Qt::Key_Up, Qt::NoModifier).nativeVirtualKey();
You are not catching a real key even but try into to convert from qt::key_up to sort of like VK_ARROWUP ?
I do not think this can work since the real event provides the sym key and here you just construct a fake one so this info is not there.
@mrjj Thank for reply.
I'm sorry. I meant this in last message: QKeyEvent(QEvent::KeyPress, Qt::Key_Up, Qt::NoModifier).nativeScanCode(); It had not worked too, and now I almost understand why. Explain please, what is sym key? Symbol key?
I don't know am I right, but I think that it hadn't worked because real event calls this constructor with ready nativeVirtualKey and scanCode:
QKeyEvent::QKeyEvent(Type type, int key, Qt::KeyboardModifiers modifiers, quint32 nativeScanCode, quint32 nativeVirtualKey, quint32 nativeModifiers, const QString & text = QString(), bool autorep = false, ushort count = 1)
I thought, this codes are calculating somewhere In constructor, but as i see - they need to be listed when constructor is called.I get good nativeVirtualKey in keyboardEvent and it also equals 37, 38, 39, 40, but I wanted to get constants anywhere else and not to use Windows constants. Is there any possible way?
-
@mrjj Thank for reply.
I'm sorry. I meant this in last message: QKeyEvent(QEvent::KeyPress, Qt::Key_Up, Qt::NoModifier).nativeScanCode(); It had not worked too, and now I almost understand why. Explain please, what is sym key? Symbol key?
I don't know am I right, but I think that it hadn't worked because real event calls this constructor with ready nativeVirtualKey and scanCode:
QKeyEvent::QKeyEvent(Type type, int key, Qt::KeyboardModifiers modifiers, quint32 nativeScanCode, quint32 nativeVirtualKey, quint32 nativeModifiers, const QString & text = QString(), bool autorep = false, ushort count = 1)
I thought, this codes are calculating somewhere In constructor, but as i see - they need to be listed when constructor is called.I get good nativeVirtualKey in keyboardEvent and it also equals 37, 38, 39, 40, but I wanted to get constants anywhere else and not to use Windows constants. Is there any possible way?
@Dani
Hi
yes sym = symbol key. bad name. its more like native key value.
The reason its not working is that the native/os/nativeVirtualKey is part of the real os event and added to the
QKeyEvent class when a real OS event happens.
So I do not think creating one will contain the info you want.I have never seen such function but Qt is big so there might be something.
You might be able to borrow some from KDE
http://api.kde.org/4.x-api/kdelibs-apidocs/kdeui/html/kkeyserver__win_8cpp_source.htmlCan I ask why you want native values and cant just use Qt::Key_xx ?
-
@Dani
Hi
yes sym = symbol key. bad name. its more like native key value.
The reason its not working is that the native/os/nativeVirtualKey is part of the real os event and added to the
QKeyEvent class when a real OS event happens.
So I do not think creating one will contain the info you want.I have never seen such function but Qt is big so there might be something.
You might be able to borrow some from KDE
http://api.kde.org/4.x-api/kdelibs-apidocs/kdeui/html/kkeyserver__win_8cpp_source.htmlCan I ask why you want native values and cant just use Qt::Key_xx ?
@mrjj With keyboardEvent I store pressed keys.I need to react on English and non-English keyboard the same. So I wanted to use nativeVirtualKey to perform the same reaction on same keys (but in different language). But it hadn't worked for arrow keys: Qt::Key_Up has value 16 777 235. So I needed to do something with that.
-
hi
oh, i thought Qt would send same Qt::Key_xx
regardless of the actual keyboard.Good to know it wont.