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

Are the keybindings configurable? #13

Open
rosshadden opened this issue Mar 7, 2019 · 4 comments
Open

Are the keybindings configurable? #13

rosshadden opened this issue Mar 7, 2019 · 4 comments

Comments

@rosshadden
Copy link

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

@alexozer
Copy link
Owner

alexozer commented Mar 7, 2019

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()

@rosshadden
Copy link
Author

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.

@alexozer
Copy link
Owner

alexozer commented Mar 8, 2019

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.

@bryan-souza
Copy link

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.

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

No branches or pull requests

3 participants