PDA

View Full Version : Keyboard combination of ctrl+shift+alt not supported?



christer
8th March 2010, 10:23
I'm running PC-BSD 8.0 operating system at work which use KDE 4.3.5 and thus Qt.

I have an application (developed in java, but not Qt related) that requires me to press-hold ctrl+shift+alt in certain situations and then the click the right mouse button. But it doesn't work. I tried to see if the combination worked in "global keyboard shortcuts" in the system settings of KDE. When I try to set a custom combination for any of the action and press these three modifier keys at the same time I get (instantaneously) a popup warning window saying:
"The key you just pressed is not supported by Qt."
Is that true? That is is impossible to get it to work (short of implementing it in the Qt toolkit if it really is not supported)?
If it is supported but Qt in general, anyone have an idea where I should start digging, perhaps PC-BSD <--> KDE issue?

I have a few colleagues thinking I should run Gnome (and thus GTK+, they use Ubuntu Linux)... Can anyone save me?

boudie
8th March 2010, 21:40
The combination of Ctrl+Shift+Alt can't be used as a keyboard shortcut, because all three are Keyboard Modifiers which must be followed by a "normal" key. Hence Ctrl+Shift+Alt+"A" would be a valid combination.
If your program handles mouse events correctly, it should check the state of these Keyboard Modifiers at every mouse event and accept Ctrl+Shift+Alt as a valid combination.

christer
9th March 2010, 10:08
Yes the application handles it correctly (when the mouse event is fired it checks that the right mouse button is clicked and all three modifier keys). It works on windows and linux with gnome(GTK+).
The question was if KDE's error message blaming Qt was correct or not. The global keyboard shortcut setup doesn't even allow me to press e.g. ctrl+shift+alt+A, when I hold down the three modifier keys the error message is shown and the assignment of a shortcut is blocked.

I would assume any good toolkit for handling keyboard input supports all three (alt, shift, ctrl) modifiers keys at the same time. Perhaps I should blame Freebsd in some way, perhaps the combination of these keys is propagated up to Qt as some other strange key combination, not what Qt would expect from ctrl+shift+alt being pressed.

boudie
9th March 2010, 12:38
That must be a new "feature" of KDE 4.3.5, because I'm using KDE 3.5 and I can make a ctrl+shift+alt+A shortcut without any problem.
Maybe it's better to ask this question to a specific KDE-forum?


I just tested a few shortcuts in my own program (using Qt 4.6.0) and a few strange things came out:
shift + alt + A = OK
shift + ctrl + A = OK
alt + ctrl + A = NOT OK
but:
alt + ctrl + B = OK huh?
shift + ctrl + alt + A = OK!!!
The last one proofs that Qt has no problem with shift+ctrl+alt.

All tested like this:


testAction = new QAction(this);
testAction->setShortcut(Qt::SHIFT | Qt::CTRL | Qt::ALT | Qt::Key_A);
this->addAction(testAction);
connect(testAction, SIGNAL(triggered()), this, SLOT(textChanged()));

I'll leave this problem to people who know more about it...
Sorry I couldn't help you. ;)

JD2000
9th March 2010, 14:08
You may want to have a play with the QKeyEvent class, this lets you examine the keycodes directly.

christer
10th March 2010, 15:50
Ok I managed to slam together a little program reading the QKeyEvent, my first venture into Qt.

I discovered that the problem is not control+shift+alt, but in fact the shorter alt+shift (or shift+alt).
The strange thing is that QKeyEvent::key() returns 0xffffffff, which is not listed as anyone on the enum Qt::Key (http://doc.trolltech.com/4.6/qt.html#Key-enum) page.
KDE probably complains when it got this 0xffffffff and says Qt doesn't support it.

But the native*() functions doesn't return any value that is too strange, but perhaps they are. Can anyone download and compile program included and try the same thing and post the output? Would be grateful, because if they differ in the native codes (shift+alt/alt+shift) I have to start digging down into FreeBSD lower levels and see what is cause.

Edit: Forgot to mention. I have a Swedish keyboard. In the regional settings I tested changing layout to US keyboard layout. The only difference is the nativeModifier that gets its value "prefixed" with 0x20 (without the 0x, but it's hexadecimal).
I don't have any real English keyboard to try with.
Edit 2: Couldn't attach a file, changed the source code dialog to include the whole program.


Here is the code of the interesting function and then some output (with comments I made to clarify).



#include <QApplication>
#include <QWidget>
#include <QKeyEvent>
#include <stdio.h>

class SenseKey : public QWidget
{
public:
SenseKey (QWidget *parent, Qt::WindowFlags);

protected:
void keyPressEvent (QKeyEvent *);
};



SenseKey::SenseKey (QWidget *parent, Qt::WindowFlags flags) :
QWidget (parent, flags) {}

void SenseKey::keyPressEvent (QKeyEvent *qke)
{
qke->accept();
switch (qke->key())
{
case Qt::Key_B:
printf("----------------------------------------------------------------------------------------\n");
return;
case Qt::Key_unknown:
printf("Unkown key\n");
return;
case Qt::Key_Shift:
printf("key(): Shift\t");
break;
case Qt::Key_Control:
printf("key(): Control\t");
break;
case Qt::Key_Alt:
printf("key(): Alt\t");
break;
default:
printf("key(): %x\t", qke->key());
}
printf("nativeModifiers(): %x\t", qke->nativeModifiers());
printf("nativeScanCode(): %x\t", qke->nativeScanCode());
printf("nativeVirtualKey(): %x\n", qke->nativeVirtualKey());
return;
}


int main(int argc, char *argv[])
{
QApplication app(argc, argv);

SenseKey *sens = new SenseKey(0, 0);

//app.setMainWidget (sens);

sens->show();
return app.exec();
}


To differentiate better I press the 'b' key between each attempt so you others can see which keys were triggered in each combined stroke.



key(): Control nativeModifiers(): 10 nativeScanCode(): 25 nativeVirtualKey(): ffe3
----------------------------------------------------------------------------------------
key(): Shift nativeModifiers(): 10 nativeScanCode(): 32 nativeVirtualKey(): ffe1
----------------------------------------------------------------------------------------
key(): Alt nativeModifiers(): 10 nativeScanCode(): 40 nativeVirtualKey(): ffe9
----------------------------------------------------------------------------------------
// Press-and-hold Control and press Shift
key(): Control nativeModifiers(): 10 nativeScanCode(): 25 nativeVirtualKey(): ffe3
key(): Shift nativeModifiers(): 14 nativeScanCode(): 32 nativeVirtualKey(): ffe1
----------------------------------------------------------------------------------------
// Press-and-hold Alt and press Control
key(): Alt nativeModifiers(): 10 nativeScanCode(): 40 nativeVirtualKey(): ffe9
key(): Control nativeModifiers(): 18 nativeScanCode(): 25 nativeVirtualKey(): ffe3
----------------------------------------------------------------------------------------
// Press-and-hold Shift and press Alt
key(): Shift nativeModifiers(): 10 nativeScanCode(): 32 nativeVirtualKey(): ffe1
key(): ffffffff nativeModifiers(): 11 nativeScanCode(): 40 nativeVirtualKey(): fe0a
----------------------------------------------------------------------------------------
// Press-and-hold Alt and press Shift
key(): Alt nativeModifiers(): 10 nativeScanCode(): 40 nativeVirtualKey(): ffe9
key(): ffffffff nativeModifiers(): 18 nativeScanCode(): 32 nativeVirtualKey(): fe0a
----------------------------------------------------------------------------------------
// Press-and-hold Control, press-and-hold Shift and press Alt
key(): Control nativeModifiers(): 10 nativeScanCode(): 25 nativeVirtualKey(): ffe3
key(): Shift nativeModifiers(): 14 nativeScanCode(): 32 nativeVirtualKey(): ffe1
key(): ffffffff nativeModifiers(): 15 nativeScanCode(): 40 nativeVirtualKey(): fe0a
----------------------------------------------------------------------------------------
// Press-and-hold Control, press-and-hold Alt and press Shift
key(): Control nativeModifiers(): 10 nativeScanCode(): 25 nativeVirtualKey(): ffe3
key(): Alt nativeModifiers(): 14 nativeScanCode(): 40 nativeVirtualKey(): ffe9
key(): ffffffff nativeModifiers(): 1c nativeScanCode(): 32 nativeVirtualKey(): fe0a
----------------------------------------------------------------------------------------