-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ability to send key presses over HDMI
Allows sending key press events to selected destination device (TV, receiver, player, etc.)
- Loading branch information
Showing
4 changed files
with
159 additions
and
0 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
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,62 @@ | ||
/* | ||
Use arrow keys from your PC as arrows buttons to control TV. | ||
*/ | ||
|
||
const cecInit = require('./shared/init'); | ||
cecInit().then(test); | ||
|
||
process.stdin.setRawMode(true); | ||
process.stdin.setEncoding('utf8'); | ||
|
||
var enabled = true; | ||
|
||
function test(obj) | ||
{ | ||
console.log('--- Control dev1 with keyboard arrow keys, select with "Spacebar" ---\n'); | ||
|
||
process.stdin.on('data', async(key) => | ||
{ | ||
if(!enabled) return; | ||
|
||
enabled = false; | ||
|
||
/* Read arrow keys */ | ||
if(key.charCodeAt(0) === 27 && key.charCodeAt(1) === 91) | ||
{ | ||
switch(key.charCodeAt(2)) | ||
{ | ||
case 65: | ||
await obj.controller.dev1.sendKey('up'); | ||
break; | ||
case 66: | ||
await obj.controller.dev1.sendKey('down'); | ||
break; | ||
case 67: | ||
await obj.controller.dev1.sendKey('right'); | ||
break; | ||
case 68: | ||
await obj.controller.dev1.sendKey('left'); | ||
break; | ||
default: | ||
break; | ||
} | ||
} | ||
else | ||
{ | ||
switch(key) | ||
{ | ||
case '\u0020': // "Enter" key | ||
await obj.controller.dev1.sendKey('select'); | ||
break; | ||
case '\u0003': // Close with "Ctrl+c" | ||
/* In stdin RAW mode spawned process will not be closed on exit and must be closed manually */ | ||
obj.cec.closeClient().then(() => process.exit(0)); | ||
break; | ||
default: | ||
break; | ||
} | ||
} | ||
|
||
enabled = true; | ||
}); | ||
} |