KeyboardManager¶
Description¶
The KeyboardManager object manages Keyboard devices available on the system. It automatically populates and updates the devices list. To use a certain device, e.g. selected by properties such as Keyboard.vendorIdentifier or Keyboard.productIdentifier, connect to its signals as shown in the example below.
This object was introduced in InCore 2.3.
› Inherits: | Object |
---|
Properties¶
Signals¶
devicesDataChanged(SignedInteger index)¶
This signal is emitted whenever the List.dataChanged() signal is emitted, i.e. the item at index
in the devices list itself emitted the dataChanged() signal.
Example¶
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()
} )
}
}
}