C
キーボード入力の処理
システムにキーボードが搭載されている場合、`PlatformInterface::handleKeyEvent()` メソッドに `Qul::EventQueue` を指定することで、キーイベントをアプリケーションに送信できます。Qt Quick のUltraliteエンジンは、キーイベントを解釈することなく、さらなる処理のためにアプリケーションにキーイベントを転送します。アプリケーション内の任意の視覚的なQMLアイテムがキーイベントを受信できます。詳細については、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ライセンスの下で利用可能です。
詳細はこちら。