结构定义如下:
namespace QEvdevKeyboardMap {
struct Mapping {
quint16 keycode;
quint16 unicode;
quint32 qtcode;
quint8 modifiers;
quint8 flags;
quint16 special;
};
#define MAX_COMPOSING_STEPS 6
struct Composing {
quint8 type;
quint32 result;
struct
{
quint32 qtcode; // QT code
bool pressed; // Pressed or released
quint32 holdtime; // Hold time, unit: ms
}step[MAX_COMPOSING_STEPS+1]; // The last one mark end
};
}这里定义的是一个组合按键的结构,后面的这个数组长度可以变,实例如下:
#define ONE_KEY_LONG_PRESS 0x01
#define TWO_KEY_LONG_PRESS 0x02
#define THREE_KEY_LONG_PRESS 0x03
const QEvdevKeyboardMap::Composing QEvdevKeyboardHandler::s_keycompose_default[] = {
{ONE_KEY_LONG_PRESS, 0x01000290,{{0x0100024a,true,5000},{0,false,0}}}, // One key long press
{TWO_KEY_LONG_PRESS, 0x01000291,{{0x01000265,true,2000},{0x01000264,true,2000},{0,false,0}}}, // Two key long press
{TWO_KEY_LONG_PRESS, 0x01000292,{{0x01000260,true,2000},{0x0100025f,true,2000},{0,false,0}}}, // Two key long press
{THREE_KEY_LONG_PRESS, 0x01000293,{{0x01000267,true,2000},{0x01000266,true,2000},{0x01000265,true,2000},{0,false,0}}}, // Threee key long press
};
由于这个数组的成员可能很多,所以它被定义在一个单独的头文件中。注意这里对该数组进行初始化时的引用方法:
const QEvdevKeyboardMap::Composing QEvdevKeyboardHandler::s_keycompose_default[]这里用了一个命名空间 QEvdevKeyboardHandler, s_keycompose_default [] 定义在类 QEvdevKeyboardHandler中
class QEvdevKeyboardHandler : public QObject
{
......
用起来还是蛮方便的:static const QEvdevKeyboardMap::Composing s_keycompose_default[];};
m_keycompose = s_keycompose_default;
m_keycompose_size = sizeof(s_keycompose_default) / sizeof(s_keycompose_default[0]);