alexozer / flitter

A Livesplit-inspired speedrunning split timer for Linux/macOS terminal. Supports global hotkeys.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Are the keybindings configurable?

rosshadden opened this issue · comments

I love (and need) the global hotkeys, but the specific keys used will never work for everyone. Are they configurable?

Hi! I do agree that having something like a configuration file for keybindings and layout settings and such would be more ideal, unfortunately I don't have time to add major features to this timer at the moment.

So right now the only way to do this is to tweak the code. You'd need to change this function. For example, in the Idle state, if you wanted to change the keybindings from "q to quit, j or space to start" to "left shift to start, right alt to quit", you'd go from this:

| Idle -> (
        match key_str with
        | "space" | "j" -> {
            timer with
            state = Timing ([||], t)
          }
        | "q" -> raise Stdlib.Exit
        | _ -> timer
)

to this:

| Idle -> (
        match key_str with
        | "shift" -> {
            timer with
            state = Timing ([||], t)
          }
        | "alt_r" -> raise Stdlib.Exit
        | _ -> timer
)

So the keys for left shift, left alt etc are "shift", "alt", "ctrl", and for the right-side equivalents, they are "shift_r", "alt_r", "ctrl_r".

You'd have to make similar changes for the rest of the code block I linked in the previous reply. Afterwards, you can just compile and install Flitter like normal.

You can also use this script to discover which keycodes to use:

import time
import sys
from pynput import keyboard


def on_press(key):
    try:
        t = time.time()
        try:
            # Alphanumeric key pressed
            print('{} {}'.format(t, key.char), flush=True)
        except AttributeError:
            # Special key pressed
            key_name = str(key)[4:] # Strip "Key."
            print('{} {}'.format(t, key_name), flush=True)
    except:
        sys.exit(0)

# Collect events until released
with keyboard.Listener(on_press=on_press) as listener:
    try:
        while True:
            t = time.time()
            print('{} heartbeat'.format(t))
            time.sleep(1)
    except:
        sys.exit(0)
listener.join()

That was sufficient for me, thanks. Unfortunately most special keys are recognized as None (likely an issue that should be filed with the key library you're using). Since I'm running a PC game with it's own mappings (doesn't even have that many, but also involves typing some arbitrary text) I struggled with finding keys that would work for me. I ended up using the F keys which were detected properly.

Interesting, I tried myself and it seems that media keys are not recognized by this library. Thanks for pointing that out.

I'll leave this issue open as it's something that ideally should be fixed at some point.

Heya alexozer, i had an idea: what about using JSON or XML as a configuration file? I'm not a OCaml programmer, but i think that, if it's possible to implement, it would be a lot easier to tweak keybindings.