我需要收听蓝牙键盘发送到我的设备的原始命令/按键,如果可能的话,防止它们“传播”到系统的其余部分。
基本上,我用 Node.js 和 coffee-script 编写了一些东西,它接收来自stdin
我的飞利浦 Hue 灯泡的按键并控制它。它看起来像这样:
keypress = require 'keypress'
# Setup keypress events
keypress process.stdin
process.stdin.on 'keypress', (character, key) ->
switch character
when 'l' then hue.decreaseTemp()
when 'r' then hue.increaseTemp()
when 'u' then hue.increaseBri()
when 'd' then hue.decreaseBri()
when 'b' then hue.turnOff()
# Exit on ctrl-c
if key?.ctrl and key.name is 'c'
process.stdin.pause()
它的功能有效,但它不是很有用,因为它接收来自标准输入的输入,从而阻止它在后台运行。
在没有焦点的窗口的情况下,我该怎么做才能使这个接收输入?
我的偏好是在我的 Mac 上运行 Node.js 或 Python 中的某些东西,但如果需要,我愿意切换语言或在我的 Raspberry Pi 上运行