作者:mobiledu2502927537 | 来源:互联网 | 2023-05-19 08:07
Ineedtolistentotherawcommandskeypressesthatabluetoothkeyboardsendstomydeviceandif
I need to listen to the raw commands/keypresses that a bluetooth keyboard sends to my device and if possible, prevent them from 'propagating' to the rest of the system.
我需要听一下蓝牙键盘发送到我的设备的原始命令/按键,如果可能的话,阻止它们“传播”到系统的其余部分。
Basically, I've written something with Node.js and coffee-script that receives keypresses from stdin
and controls my Philips Hue lightbulbs. It looks something like this:
基本上,我用Node.js和coffee-script编写了一些东西,它从stdin接收按键并控制我的Philips 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()
It's functionality works, but it's not very useful as it receives input from stdin, preventing it from running in the background.
它的功能很有用,但它不是很有用,因为它从stdin接收输入,阻止它在后台运行。
What could I do to make this receive input without the window having focus?
如果没有焦点窗口,我该怎么做才能接收输入?
My preference is for something in Node.js or Python to run on my Mac, but I'm willing to switch languages or run on my Raspberry Pi if need be
我的偏好是在我的Mac上运行Node.js或Python中的某些东西,但是如果需要,我愿意切换语言或在我的Raspberry Pi上运行
2 个解决方案