TKeyEvent
Support
Supported from 5.0
Description
Key event details.
When processing a TKeyEvent
, the TStdScanCode
in iScanCode
should usually be ignored in favour of the TKeyCode
in iCode
. Using iScanCode
would bypass the keyboard mapping and any FEP that happens to be installed. The exceptions to this general rule are games where the positions of the keys are more important than their translations, and FEPs that are implementing keyboard maps themselves. In these cases, if the iCode
is used rather than iScanCode
to determine the key pressed, there will be two unfortunate consequences. Firstly, the low-level keyboard mapping might re-arrange the mapping that you are trying to impose. Secondly, you will subvert the CTRL+number method of entering Unicode literals.
注释:
当处理一个TKeyEvent时,TStdScanCode中的iScanCode通常应该被忽略而赞成用TKeyCode中的iCode。用iScanCode可以绕过键盘映射和任何已经安装 的FEP(A front-end processor)。这个规则的例外情况是游戏,因为游戏中键盘的方位比它们实际的值更重要,还有FEP中,它们已经实现了键盘映射。在这些情况下,用iCode去决定按键,会有两个意外的后果。首先,底层的键盘映射机制可能会重新布置键盘映射。其次,你会破坏输入Unicode字符的CTRL+number方法。
Members
Defined in TKeyEvent
:
iCode
, iModifiers
, iRepeats
, iScanCode
Member data
TUint iCode
Description
The character code generated for an EEventKey
, or 0 for a down or up event.
Key codes for special keys are defined in TKeyCode
.
对应一个EEventKey产生的字符码,当按下或释放按键的时候值为0( 这点需要注意,我测试的时候,没按键的时候屏幕上值为0,只有当键被按超过几s时才会有相应的值产生,当释放按键的时候值也为0,所以你如果写成下面的代码值就始终为0,测试不出来实际的值:
if( aType == EEventKeyDown ){
TBuf<40> scanCode;
scanCode.AppendNum(aKeyEvent.iCode);
scanCode.operator +=_L(" iScanCode is pressed down!");
CEikonEnv::Static()->InfoMsg(scanCode);
}
所以应该写成下面这样:
if( aType == EEventKey ){
TBuf<40> scanCode;
scanCode.AppendNum(aKeyEvent.iCode);
scanCode.operator +=_L(" iScanCode is pressed down!");
CEikonEnv::Static()->InfoMsg(scanCode);
}
当aType为EEventKeyDown或EEventKeyUp时,iCode的值均为0
) 。
特定按键的Key codes在TKeyCode中定义。
TUint iModifiers
Description
State of modifier keys and pointing device. Modifier keys are defined in TEventModifier
.
TInt iRepeats
Description
Count of auto repeats generated.
0 means an event without repeats. 1 or more means "this many auto repeat events". It is normal to ignore this value and treat it as a single event.
TInt iScanCode
Description
The scan code of the key that caused the event.
Standard scan codes are defined in TStdScanCode
.