.. _object_KeyboardManager: :index:`KeyboardManager` ------------------------ Description *********** The KeyboardManager object manages :ref:`Keyboard ` devices available on the system. It automatically populates and updates the :ref:`devices ` list. To use a certain device, e.g. selected by properties such as :ref:`Keyboard.vendorIdentifier ` or :ref:`Keyboard.productIdentifier `, connect to its signals as shown in the example below. This object was introduced in InCore 2.3. :**› Inherits**: :ref:`Object ` Overview ******** Properties ++++++++++ .. hlist:: :columns: 1 * :ref:`devices ` * :ref:`Object.objectId ` * :ref:`Object.parent ` Methods +++++++ .. hlist:: :columns: 1 * :ref:`Object.deserializeProperties() ` * :ref:`Object.fromJson() ` * :ref:`Object.serializeProperties() ` * :ref:`Object.toJson() ` Signals +++++++ .. hlist:: :columns: 1 * :ref:`devicesDataChanged() ` * :ref:`Object.completed() ` Properties ********** .. _property_KeyboardManager_devices: .. _signal_KeyboardManager_devicesChanged: .. index:: single: devices devices +++++++ This property holds all available :ref:`Keyboard ` objects. :**› Type**: :ref:`List `\<:ref:`Keyboard `> :**› Signal**: devicesChanged() :**› Attributes**: Readonly Signals ******* .. _signal_KeyboardManager_devicesDataChanged: .. index:: single: devicesDataChanged devicesDataChanged(SignedInteger index) +++++++++++++++++++++++++++++++++++++++ This signal is emitted whenever the :ref:`List.dataChanged() ` signal is emitted, i.e. the item at ``index`` in the :ref:`devices ` list itself emitted the dataChanged() signal. .. _example_KeyboardManager: Example ******* .. code-block:: qml import InCore.Foundation 2.5 import InCore.IO 2.5 Application { KeyboardManager { id: keyboardManager onDevicesChanged: { console.log("Keyboards:") for( var i = 0; i < devices.length; ++i ) { console.log("Input device file:", devices[i].inputDeviceFile, "\n\tName:", devices[i].name, "\n\tVendor identifier:", devices[i].vendorIdentifier, "\n\tProduct identifier:", devices[i].productIdentifier, "\n\tPhysical location:", devices[i].physicalLocation, "\n\tUSB location:", devices[i].usbLocation, ) devices[i].enabled = devices[i].vendorIdentifier > 0 devices[i].keyPressed.connect( (key, modifiers) => { if(modifiers & Keyboard.ShiftModifier) { console.log("Key", key, "with Shift pressed.") } else { console.log("Key", key, "pressed.") } } ) devices[i].keyReleased.connect((key) => { console.log("Key", key, "released.") } ) devices[i].textEntered.connect((text) => { console.log(("Text entered: \"%1\"").arg(text)) } ) } } } // implement a barcode scanner object which buffers subsequently entered characters // until no more characters are entered for a certain time Object { id: barcodeScanner onBarcodeScanned: console.log("Barcode scanned:", barcode) signal barcodeScanned(string barcode) property Keyboard device property string barcodeCharacters readonly property var inputTimer : Timer { interval: 200 repeat: false running: false onTriggered: { parent.barcodeScanned(parent.barcodeCharacters) parent.barcodeCharacters = "" } } Select on device { source: keyboardManager.devices // select barcode scanner from available input devices by vendor and product identifier select: item.vendorIdentifier === 0x0581 && ( item.productIdentifier === 0x0110 || item.productIdentifier === 0x0115 ) } onDeviceChanged: { if(device) device.textEntered.connect( (text) => { barcodeCharacters += text inputTimer.restart() } ) } } }