This repository has been archived by the owner on Jun 19, 2021. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
17 changed files
with
214 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,5 @@ node_modules | |
.DS_Store | ||
*.swp | ||
dist | ||
*.log | ||
package-lock.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
/* This file says HID device, which is redundant, a lot. You'll get over it. | ||
*/ | ||
|
||
window.$ = window.jQuery = require('jquery'); | ||
const bootstrap = require('bootstrap'); | ||
|
||
const {ipcRenderer} = require('electron'); | ||
const remote = require('electron').remote; | ||
const BrowserWindow = remote.BrowserWindow; | ||
const HID = require('node-hid'); | ||
|
||
/* HTML Entities | ||
*/ | ||
let $status = $('#status'); | ||
let $keyboardChooserLabel = $('#keyboard-chooser-label'); | ||
let $keyboardList = $('#keyboard-list'); | ||
|
||
/* State variables | ||
*/ | ||
let currentHidDevice; | ||
|
||
/* Helpful functions | ||
*/ | ||
function clearConsole() { | ||
$status.text(''); | ||
} | ||
|
||
function writeConsole(text) { | ||
/* Write a line to the console window. Should only be used to write | ||
* log output. | ||
*/ | ||
$status.append(text); | ||
$status.scrollTop(1E10); // Scroll a lot so we don't have to calculate. | ||
} | ||
|
||
function process_usb_packet(data_array) { | ||
/* Process a USB message. | ||
*/ | ||
let message = ''; | ||
for (let char of data_array) { | ||
message += String.fromCharCode(char); | ||
} | ||
writeConsole(message); | ||
} | ||
|
||
function handleError(error) { | ||
/* Called when there's an error from the HID device | ||
*/ | ||
console.log('HID error:', error); | ||
writeConsole('\n<b>Connection to keyboard closed:</b> ' + error); | ||
currentHidDevice.close(); | ||
currentHidDevice = null; | ||
$keyboardChooserLabel.html('Choose Keyboard'); | ||
} | ||
|
||
function selectKeyboard(manufacturer, product, path) { | ||
console.log('selectKeyboard: ', manufacturer, product, path); | ||
clearConsole(); | ||
currentHidDevice = new HID.HID(path); | ||
currentHidDevice.on("data", process_usb_packet); | ||
currentHidDevice.on("error", handleError); | ||
$keyboardChooserLabel.html('<b>Manufacturer:</b> ' + manufacturer + ', <b>Keyboard:</b> ' + product); | ||
writeConsole('<b>Connected to ' + manufacturer + ' ' + product + ': ' + path + '</b>\n'); | ||
} | ||
|
||
function populateKeyboardDropdown() { | ||
/* Empty the keyboard list and repopulate it. | ||
*/ | ||
let keys = []; | ||
let keyboards = {} | ||
let devices = HID.devices(); | ||
console.log('devices:', devices); | ||
|
||
for (let device of devices) { | ||
if (device.usage == 116) { // Look for USB devices with hid_listen usage | ||
console.log('device:', device) | ||
keys.push(device.path); | ||
keyboards[device.path] = device; | ||
} | ||
} | ||
|
||
keys.sort(); | ||
$keyboardList.empty(); | ||
for (let key of keys) { | ||
keyboard = keyboards[key]; | ||
let select_opts = "'" + keyboard.manufacturer + "', '" + keyboard.product + "', '" + keyboard.path + "'"; | ||
let dropdown_entry = keyboard.manufacturer + '(0x' + keyboard.vendorId.toString(16).toUpperCase() + '): ' + keyboard.product + '(0x' + keyboard.productId.toString(16).toUpperCase() + ')'; | ||
|
||
$keyboardList.append('<li><a href="#" onclick="selectKeyboard(' + select_opts + ');">' + dropdown_entry + '</a></li>'); | ||
} | ||
|
||
window.setTimeout(populateKeyboardDropdown, 3000); | ||
} | ||
|
||
$(document).ready(function() { | ||
/* main() | ||
*/ | ||
$("<link/>", {rel: "stylesheet", type: "text/css", href: "../MainWindow/themes/" + ipcRenderer.sendSync('get-setting-theme') + ".css"}).appendTo("head"); | ||
|
||
populateKeyboardDropdown(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>hid_listen</title> | ||
<link href="../../node_modules/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet"> | ||
<link href="style.css" rel="stylesheet"> | ||
</head> | ||
<body> | ||
<div id="keyboard-chooser-div" class="dropdown"> | ||
<button class="btn btn-default dropdown-toggle" type="button" id="keyboard-chooser" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true"> | ||
<span class="caret"></span> <span id="keyboard-chooser-label">Choose Keyboard</span> | ||
</button> | ||
<ul class="dropdown-menu" aria-labelledby="keyboard-chooser" id="keyboard-list"> | ||
<li><a href="#">No Keyboards Detected</a></li> | ||
</ul> | ||
</div> | ||
<span id="status"></span> | ||
<script src="console.js"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#status { | ||
font-family: monospace; | ||
font-size: 12px; | ||
position: absolute; | ||
left: 14px; | ||
right: 14px; | ||
top: 50px; | ||
bottom: 14px; | ||
border-radius: 2px; | ||
overflow-x: scroll; | ||
overflow-y: scroll; | ||
white-space: pre-wrap; | ||
padding: 7px; | ||
-webkit-app-region: no-drag; | ||
} | ||
|
||
#status, #status b { | ||
-webkit-user-select: text; | ||
} | ||
|
||
#keyboard-chooser { | ||
width: 100%; | ||
text-align: left; | ||
} | ||
|
||
#keyboard-chooser-div { | ||
position: absolute; | ||
top: 10px; | ||
left: 14px; | ||
right: 14px; | ||
height: 24px; | ||
border-radius: 6px; | ||
margin: 0; | ||
padding: 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,7 @@ html, body, .modal-content { | |
font: icon; | ||
} | ||
|
||
.dropdown-menu { | ||
.menu { | ||
font: menu; | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters