Coder Social home page Coder Social logo

maxakuru / btkb Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 46 KB

Bluetooth keyboard emulator service and FIFO client for sending keystrokes

Shell 5.36% Python 94.64%
fifo fifo-client bluetooth ir-codes firestick hid bluetooth-controller emulator python

btkb's Introduction

btkb

A bluetooth HID keyboard emulator service and FIFO client.

Goal

The purpose of this project was to create a way to relay messages to control an Amazon Firestick quickly (since it's for a TV remote). It's quite possible this isn't the fastest way, but it's certainly faster than using adb shell keyinput or sendevent.

I'm currently using this on a Raspberry Pi Zero W to dispatch commands received from IR signals on a TV remote. I went with the FIFO passthrough because the remote's protocol is DirecTV, and either I'm too stupid or lazy to figure out any other way to use it (ie. ir-keytable) than "raw codes" with LIRCD. Ultimately, the btkb command in this repo is used by irexec. This setup still allows for some IR codes to be "exchanged" - for example, specific buttons on a remote can lead to irexec emitting different IR codes for devices that have no other way to commmunicate. This story has little to do with the actual code here, but I hope you enjoyed it.

Setup

  1. Get the repo
git clone [email protected]:maxakuru/btkb.git
  1. Enable bluetooth if needed
sudo hciconfig hcio up
  1. Copy config.ini.example and rename to config.ini

  2. Configure config.ini how you like, at least the device address is needed

Note: To get the bluetooth device address, use sudo hciconfig hci0 -a and look for BD Address.

  1. Run the setup script (or set it up however you want)
/bin/bash setup.sh
  1. Pair your device
sudo /usr/bin/bluetoothctl

Then

agent on
default-agent
pairable on
discoverable on

And leave this terminal running.

Find your device in the bluetooth device list, pair, accept Back in the terminal, accept the pairing code with yes.

  1. Send keystrokes via fifo A convenience script is installed with the setup script, but really it just pushes whatever the arguments you provide into a fifo. This fifo is then read, line by line, by the FifoClient, converted into HID bytestrings and sent to the connected device. The fifo is owned by uid/gid 1000, but depending on step 2, you may need sudo.

Sample commands

Press down "enter":

btkb KEY_ENTER

Press down "enter", release all keys:

btkb KEY_ENTER ACT_RELEASE

Press down "enter", hold it for a second, release:

btkb KEY_ENTER ACT_HOLD_1 ACT_RELEASE

Left ctrl + esc, then release keys and unhold "ctrl" modifier:

btkb MOD_LEFTCTRL KEY_ESC ACT_RELEASE MOD_RESET

Note: this works the same as the KEY_HOMESCREEN event on Firestick (and maybe other Android TV devices)

Alternative use

Write directly to the fifo, if you want:

echo "KEY_ENTER ACT_RELEASE" >> /tmp/btkb.fifo

Note: This requires using the same user as configured in config.ini

Credits

Not sure who this is, but very helpful!

AnesBenmerzoug/BluetoothHID

btkb's People

Contributors

maxakuru avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.