alexozer / flitter

A LiveSplit-inspired speedrunning split timer for Linux/macOS terminal. Supports global hotkeys.
MIT License
132 stars 11 forks source link

Keymaps #29

Closed hjhornbeck closed 3 days ago

hjhornbeck commented 3 years ago

This branch changes the python script that handles keymaps. It uses a different library, which allows for mice and other devices to be captured as well. It also allows custom keymaps, and a basic device filter so that a subset of plugged-in devices can control Flitter. The code that interfaces has been given a minor update, so that it now responds to categories of events rather that named buttons, an example keymap has been added, and the README has been updated.

alexozer commented 3 years ago

This looks incredible, thanks very much for this! I sure wish Livesplit had per-device binding filters too. Couple questions for you:

hjhornbeck commented 3 years ago

Shoot, this won't work on Mac OS X. I had a quick look, and there doesn't seem to be any comparable library either. What might work better here is a three-tier process that fails gracefully:

  1. If evdev is installed, use that to get global hotkeys + device choice.
  2. If not, check for pynput. If that's installed, use the old code or something like it for global hotkeys.
  3. No pynput? Just read keys via OCaml, forget about global hotkeys.

Key remapping would still work with pynput, however it uses very different codes than evdev and hooks into the keyboard after keycodes have been interpreted; the latter means that the keypad's enter acts the same as normal enter in pynput, for instance, and pressing NumLock changes the keys it reads. Supporting both libraries would mean a rethink of keymap.json's layout. It may also mean adding some capability detection code via a python call-out, so the OCaml code can detect the issue and support that third tier.

Give me a few days to mull over a new architecture.

alexozer commented 3 years ago

I see. Good luck!

jodosh commented 3 years ago

I see huge value in this functionality. I have been looking for a clean way to us the L and R shoulder triggers to control splits while playing NES games. Best of luck getting this merged in. I use linux not OSX so that is not a deal breaker for me.

hjhornbeck commented 3 years ago

That took longer than a few days, but I'm pretty happy with the current state of this branch. Both pynput and evdev can be used on my computer, and all the caveats I've run into are included in the updated documentation (TL;DR: Wayland likely breaks pynput, and evdev needs certain permissions). Give it a test on your side.

While I was working on this, I also added the ability to bind events to mouse input for pynput. There are also test programs to help build key bindings, too. Speaking of which: @jodosh, I fired up my PS4 Dual Shock and found it worked great with the new code. So maybe a keymap_evdev.json like:

{
  "BTN_TL":"undo",
  "BTN_TL2":"start-split-reset",
  "BTN_TR":"delete-last",
  "BTN_TR2":"pause-delete",
  "KEY_Q":"quit"
}

would be of some use.

BuyMyMojo commented 3 years ago

Will this be integrated? this program is near perfect but cannot be used for PC games that dont use controller because how often space and other keys in PC gaming

hjhornbeck commented 3 years ago

Will this be integrated? this program is near perfect but cannot be used for PC games that dont use controller because how often space and other keys in PC gaming

My primary use for flitter is tracking splits for Minecraft, so it works quite fine for keyboard-based games. Here's my keymap_evdev.json:

{
 "KEY_KPENTER":"start-split-reset",
 "KEY_KPPLUS": "undo",
 "KEY_KPMINUS":"delete-last",
 "KEY_KP0":    "pause-reset",
 "KEY_KPDOT":  "pause-delete",
 "KEY_KPSLASH":"quit"
}

Over months of occasional use, the worst issue I've encountered is that flitter will sometimes crash on first input. I haven't figured out why, but if I restart with the same settings I haven't had it happen a second time. I've also started testing if flitter responds to controls before I stream, so at least the bug won't show up on camera.

alexozer commented 3 days ago

I rewrote Flitter from scratch, and this is no longer an issue