[Qt-interest] Detect keyboard keys?

Bo Thorsen bo at fioniasoftware.dk
Fri Jun 17 09:33:13 CEST 2011


Den 17-06-2011 07:31, Thiago Macieira skrev:
> Em Thursday, 16 de June de 2011, às 17:26:36, John Weeks escreveu:
>> On Jun 16, 2011, at 3:30 PM, Thiago Macieira wrote:
>>
>> Thank you, Thiago.
>>
>>>> Thank you, Nikos. I use that myself. Unfortunately, it doesn't include
>>>> the caps lock key.
>>>
>>> Because the caps lock being held down isn't a modifier. The Caps Lock
>>> state is a modifier, though.
>>
>> OK. I can see the sense in that.
>>
>> Since Qt::KeyboardModifier does not contain anything about caps lock, I must
>> assume that setting the caps lock state (presumably by pressing the caps
>> lock key) turns on Qt::ShiftModifier, and Qt doesn't think we need to know
>> that it results from caps lock instead of simply pressing the shift key.
>
> No, that's not it. I meant that in X, the Caps Lock, Num Lock and Scroll Lock
> lock states are part of the modifier values. That isn't reflected in the Qt API
> though.
>
>> What if I want to test the current state of the 'a' key?
>
> Then you need to check your own state machine: have you received the KeyPress
> of that key and not the KeyRelease?

That question is useless since pressing caps in another app carries over 
to this one.

To the OP: You can't do this with Qt, you have to do it with native 
code. I tried testing for this in a password dialog once, but eventually 
I gave up.

I agree with Thiago on the qApp modifiers, and it doesn't help anyway. 
You need to both get the current state and be notified about changes to 
the caps lock state.

Bo Thorsen,
Fionia Software.

-- 

Expert Qt and C++ developer for hire
Contact me if you need expert Qt help
http://www.fioniasoftware.dk



More information about the Qt-interest-old mailing list