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

Feature request - Custom keybindings #31

Open
ghost opened this issue Oct 2, 2024 · 1 comment
Open

Feature request - Custom keybindings #31

ghost opened this issue Oct 2, 2024 · 1 comment

Comments

@ghost
Copy link

ghost commented Oct 2, 2024

I would like the ability to set custom keybindings for the application. Currently, the code responsible for handling keybindings is as follows:

document.addEventListener('keyup', function(e) {
    // alt + Z or z
    if ((e.keyCode == 90 || e.keyCode == 122) && e.altKey) {
		e.preventDefault();
        ts_undo();
    }
    // /
    if (e.key === ".") {
        clear_canvas();
    }
	// ,
    if (e.key === ",") {
        switch_visibility();
    }
    // alt + C or c
    if ((e.key === "c" || e.key === "C") && e.altKey) {
        e.preventDefault();
        switch_drawing_mode();
    }
        // alt + X or x
    if ((e.key === "x" || e.key === "X") && e.altKey) {
        e.preventDefault();
        switch_perfect_freehand();
    }
    if ((e.key === "b" || e.key === "B") && e.altKey) {
        e.preventDefault();
        switch_small_canvas();
    }
})

I am not very experienced in JavaScript, but would it be possible to modify this to allow custom keybindings?

@Rytisgit
Copy link
Owner

Hi, sorry for the late response. I am not planning to add a ui for keybinding configuration, but you have found the correct place in the code to change the keybindings. You can find the file you need to edit by going through these menus: Tools->Add-Ons->Select Ankidraw in the addons window->Press the View Files button.
image
This will then bring you to the folder containing the init.py file, which contains this same code you found and by editing it, then restarting Anki will load the addon with your changes. Doing this you can edit the keybinding to what works better for you.

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

1 participant