Ok so I'm trying to connect a bluetooth keyboard through a Chrome App. I was able to use this code and it has a status in the system tray as paired but I can't receive the data input from the keyboard. Example when I typed something in the text area using the bluetooth keyboard, it does not show anything in the text area.
This is how I used the API:
- After the App is launched it calls the startDiscovery() method where it discovers the nearby bluetooth devices, in this case the bluetooth keyboard.
- After the startDiscovery() method is finished, I am calling this function from a button click:
const getKnown = () => {
chrome.bluetooth.getDevices((devices) => {
for (var i = 0; i < devices.length; i++) {
//Displaying device names
console.log(i + ": " + devices[i].name);
}
chrome.bluetoothSocket.create(function (createInfo) {
chrome.bluetoothSocket.connect(createInfo.socketId,
address, service, () => {
if (chrome.runtime.lastError) {
console.log("getKnown Connection failed: " + chrome.runtime.lastError.message);
} else {
console.log(`successfully connected on device: ${address}`);
}
});
chrome.bluetoothSocket.onAccept.addListener(function (acceptInfo) {
console.log('onAccept...');
if (acceptInfo.socketId != createInfo.socketId)
return;
});
});
});
};
getKnownButton.onclick = () => getKnown();
The only problem I need to solve is how to get the input data from the keyboard. I'm not really sure what's wrong with the code. How can I get the input data from the keyboard?