Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keymaps #29

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open

Keymaps #29

wants to merge 7 commits into from

Conversation

hjhornbeck
Copy link

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.

hjhornbeck added 3 commits November 13, 2020 09:31
- Hotkeys can now be customized via a JSON file in the current directory.
- Only hotkeys arriving from specific devices will be registered, if requested.
@alexozer
Copy link
Owner

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

  • Does this work on macOS as well?
  • Could you remove mention of the old Python dep from the README?

@hjhornbeck
Copy link
Author

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
Copy link
Owner

I see. Good luck!

@jodosh
Copy link

jodosh commented Nov 21, 2020

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 added 4 commits November 25, 2020 17:24
- pynput can now incorporate mouse events.
- Added some python scripts to test out various configurations and python modules.
- BROKEN. Tests fine outside the harness, but crashes hard within. Debugging ongoing..
- Added a device list to test_evdev.py, as it helps with the filter.
…nd, causing Xlib and therefore pynput to fail. Tests fine on a Linux computer with X11, after correcting the prior typo.

- Updated the docs to reflect the code changes.
@hjhornbeck
Copy link
Author

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
Copy link

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
Copy link
Author

hjhornbeck commented Apr 21, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants