C
キーボード入力を扱う
システムにキーボードがある場合、Qul::EventQueue でPlatformInterface::handleKeyEvent() を使用してアプリケーションにキーイベントを送ることができます。Qt Quick Ultraliteエンジンはキーイベントを解釈することなく、アプリケーションに渡します。詳しくはKeys QML Type を参照してください。
以下はキー選択イベントを送信する例です:
struct KeyboardEvent
{
uint64_t timestamp;
Qul::PlatformInterface::KeyEventType type;
int key;
unsigned int nativeScanCode;
unsigned int modifiers;
uint32_t ucs4;
bool autorepeat;
};
class PlatformKeyboardEventQueue : public Qul::EventQueue<KeyboardEvent>
{
void onEvent(const KeyboardEvent &event) QUL_DECL_OVERRIDE
{
// Use the information stored in the custom struct shown above
// to transfer the information into the Qul engine
Qul::PlatformInterface::handleKeyEvent(event.timestamp,
event.type,
event.key,
event.nativeScanCode,
event.modifiers,
NULL,
event.autorepeat,
event.ucs4);
}
};
static PlatformKeyboardEventQueue keyboardEventQueue;
void keyboardISR()
{
// Here would be platform specific code to fetch data from the keyboard.
static KeyboardEvent event;
event.timestamp = Qul::Platform::getPlatformInstance()->currentTimestamp();
event.type = Qul::PlatformInterface::KeyPressEvent;
event.key = Qul::PlatformInterface::Key_A;
event.nativeScanCode = 0;
event.modifiers = Qul::PlatformInterface::NoKeyboardModifier;
event.ucs4 = 0x61;
event.autorepeat = false;
keyboardEventQueue.postEventFromInterrupt(event);
}注: Qt Quick Ultraliteはキーイベントのタイプ、キーコード、ネイティブスキャンコードのみをアプリケーショ ンに転送します。この例で示されている追加の引数は転送されません。
特定の Qt ライセンスの下で利用可能です。
詳細をご覧ください。