Skip to content

Conversation

@lokxii
Copy link

@lokxii lokxii commented May 7, 2023

Merged conflicts of #248

This pull request adds mouse button support on top of existing functionality in response to #195 and #245. A mouse button is made to treat as a key in config file such that writing (non-modifier) key + mouse combination not supported. It is however possible to do for example shift + alt - mouse_left.

A total of 32 keywords are added to correspond to what Carbon supports.

It is possible to use -k flag to synthesize a mouse click. However it is intentionally made to click at coordinates (-1, -1) to prevent clicking any elements on screen.

@kzvi
Copy link

kzvi commented Jun 13, 2023

I get this compiler warning which seems important:

In file included from src/skhd.c:39:
src/synthesize.c:76:24: warning: result of comparison of constant -1 with expression of type 'uint8_t' (aka 'unsigned char') is always false [-Wtautological-constant-out-of-range-compare]
    if (hotkey->button == -1) {
        ~~~~~~~~~~~~~~ ^  ~~

@lokxii
Copy link
Author

lokxii commented Jun 14, 2023

thx for pointing it out. Probably I just filtered away warnings and somehow testing was fine (or test not thorough enough)

@asmvik
Copy link
Owner

asmvik commented Jun 14, 2023

I think in cases like this it would be more appropriate to use UINT8_MAX instead of -1 to signal intent (even though -1 will have the same binary representation when stored in a uint8_t). I do think the compare with -1 is undefined behaviour unless explicitly casted to an unsigned type, and even if it is not, using the hex representation (0xFF) would be more appropriate.

There probably won't be further code changes to this repo, so it's not like I want or expect these changes to be done; just a note.

@rickswe
Copy link

rickswe commented Jan 13, 2024

There's no mouse button support? I was looking to do a middle click. I did not know that. 🤔

@palkx
Copy link

palkx commented Jan 15, 2024

@9tin9tin9 are there any updates on this? It would be very helpful to have this feature implemented. If this is blocked by something, can we resolve this? Thanks!

@lokxii
Copy link
Author

lokxii commented Jan 15, 2024

I don't think koekeishiya will merge this into master. So if you want to use this feature, maybe you can download and install skhd from my fork.

I won't be maintaining / adding new features besides merging from master because I personally is not a mouse user. However, if you have feature request about mouse hotkeys, I may consider implementing it.

@palkx
Copy link

palkx commented Jan 15, 2024

Yes, I find this pretty useful. For example, when you have a mouse with additional keys you can map those keys to switch between workspaces. On the Apple mouse, you can do this simply with gestures. @koekeishiya is it possible to merge this PR?

@Nikzt
Copy link

Nikzt commented Sep 30, 2025

For anyone looking for a workaround, I use Karabiner Elements to bind mouse buttons to key combinations I use in my config. eg:

skhdrc:

cmd - 0x1E : yabai -m space --focus next
cmd - 0x21 : yabai -m space --focus prev

Karabiner Elements rule json:

{
    "description": "Mouse 4,5 -> CMD + ], CMD + [",
    "manipulators": [
        {
            "from": {
                "modifiers": { "optional": ["any"] },
                "pointing_button": "button5"
            },
            "to": [
                {
                    "key_code": "open_bracket",
                    "modifiers": ["left_command"]
                }
            ],
            "type": "basic"
        },
        {
            "from": {
                "modifiers": { "optional": ["any"] },
                "pointing_button": "button4"
            },
            "to": [
                {
                    "key_code": "close_bracket",
                    "modifiers": ["left_command"]
                }
            ],
            "type": "basic"
        }
    ]
}

This way I can switch between workspaces with the forward/back buttons on my mouse.

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.

6 participants