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

[BUG]: Cannot bind "win" key in whkdrc #6

Open
gonglei opened this issue Feb 21, 2023 · 12 comments
Open

[BUG]: Cannot bind "win" key in whkdrc #6

gonglei opened this issue Feb 21, 2023 · 12 comments
Labels
bug Something isn't working

Comments

@gonglei
Copy link

gonglei commented Feb 21, 2023

I tried to bind the "win" key in ~/.config/whkdrc, I tried to change alt to win or super, but it does not work. How exactly can I change alt to win key in the config file?

To Reproduce
Steps to reproduce the behavior:

  1. change alt to win in whkdrc
  2. restart whkd
  3. see bug, win key bindings are not working

Expected behavior
win key should be able to be bound for shortcuts like AHK

Screenshots and Videos
Add screenshots and videos to help explain your problem.

Operating System
OS Name: Microsoft Windows 11 Pro
OS Version: 10.0.22000 N/A Build 22000

Additional context
Add any other context about the problem here.

In particular, if you have any other AHK scripts or software running that handle any aspect of window management, manipulation or hotkey binding

@gonglei gonglei added the bug Something isn't working label Feb 21, 2023
@LGUG2Z
Copy link
Owner

LGUG2Z commented Feb 21, 2023

This is quite a difficult problem and a moving goal because Microsoft really don't want users to be able to use MOD_WIN for anything.

image
https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-registerhotkey

There are some documented ways to disable certain system MOD_WIN combinations, however they don't seem like they are completely up to date. For example, I just tried setting the NoWinKeys registry entry, and Win+W still brings up the widgets overlay on Windows 11. It does, however, free up other bindings like Win+E, Win+H etc., which can then be bound as expected with whkd, eg. win + e: echo "hello"

Ultimately, you'll have to disable any pre-existing hotkeys registered by Windows yourself before trying to set them with whkd.

I may look into adding a section to the configuration and the parser to allow users to explicitly specify global hotkeys they wish to disable in the future (if UnregisterHotkey even works like that; I'm not sure), but it's very unlikely that this project will ever have a solution where whkd silently unregisters system-level hotkeys without explicit user direction.

@LGUG2Z
Copy link
Owner

LGUG2Z commented Feb 21, 2023

Mostly for my own ref in the future, this is how AHK handles MOD_WIN bindings: https://www.autohotkey.com/board/topic/121557-how-does-ahk-register-hotkeys/?p=688533

@gonglei
Copy link
Author

gonglei commented Feb 22, 2023

Thanks for your explanation. So currently whkd does not handle win key at all? there is no way to bind it in whkdrc? I am kind of used to bind it in other window managers like yabai or bspwm. alt key is heavily used in applications, there could be lots of conflicts if I have to use alt key bindings for komorebi.
For now maybe I have to AHK as the key binding app, it handles win key fine.

@LGUG2Z
Copy link
Owner

LGUG2Z commented Feb 22, 2023

whkd can bind combinations with the win key as long as they are not used by the system; however it doesn't provide a mechanism for unbinding system hotkeys using win or any other modifier.

For this particular use case (calling komorebic commands on combinations with the win/super key) I think that AHK is definitely the most frictionless way to go for now. 👌

@gonglei
Copy link
Author

gonglei commented Feb 23, 2023

so you meant there is a way to bind win key in whkd? what is the exact way of doing this? what's the name for win key? like alt/ctrl/shift? I have disabled win key bindings in system registry, I don't use them anyway.

@LGUG2Z
Copy link
Owner

LGUG2Z commented Feb 23, 2023

You can bind it using win, for example, with the following simple whkdrc:

# ~/.config/whkdrc
.shell pwsh

win + y : echo $((1 + 2) * 6)

Then I can start whkd and press the binding to have the command execute:

❯ whkd
# pressing win+y here
echo $((1 + 2) * 6)
18

However, as I mentioned, it may be the case that the registry modifications suggested by Microsoft are not completely up to date for disabling all system hotkeys that use win, so if you are still getting errors, it's because a particular hotkey is still being reserved by the system somewhere. I suggest adding each binding that you want with win one line at a time so that it's easier to identify any Windows system bindings that are still active.

@gonglei
Copy link
Author

gonglei commented Feb 24, 2023

Yes you are right, the win is the key name. I actually tried all 26 keys and found 12 of them cannot be bound in whkd, they are c f g i j k l o p u w z. It is not convenient that the vim dir keys jkl cannot be bound. I'll use AHK for now until this issue is resolved. Wondering how AHK solve this issue binding win + j etc. Below are my test lines in whkdrc, the 12 keys are commented out to allow whkd start successfully. Thanks for your help!

# try win key
#win + a : komorebic toggle-float
win + b : komorebic toggle-float
#win + c : komorebic toggle-float
win + d : komorebic toggle-float
win + e : komorebic toggle-float
#win + f : komorebic toggle-float
#win + g : komorebic toggle-float
win + h : komorebic toggle-float
#win + i : komorebic toggle-float
#win + j : komorebic toggle-float
#win + k : komorebic toggle-float
#win + l : komorebic toggle-float
win + m : komorebic toggle-float
win + n : komorebic toggle-float
#win + o : komorebic toggle-float
#win + p : komorebic toggle-float
win + q : komorebic toggle-float
win + r : komorebic toggle-float
win + s : komorebic toggle-float
win + t : komorebic toggle-float
#win + u : komorebic toggle-float
win + v : komorebic toggle-float
#win + w : komorebic toggle-float
win + x : komorebic toggle-float
win + y : komorebic toggle-float
#win + z : komorebic toggle-float

win + 1 : komorebic toggle-float
win + 2 : komorebic toggle-float
win + 3 : komorebic toggle-float
win + 4 : komorebic toggle-float
win + 5 : komorebic toggle-float
win + 6 : komorebic toggle-float
win + 7 : komorebic toggle-float
win + 8 : komorebic toggle-float
win + 9 : komorebic toggle-float
win + 0 : komorebic toggle-float

win + shift + a : komorebic toggle-float
win + ctrl + a : komorebic toggle-float
win + alt + a : komorebic toggle-float
#win + alt + shirt + a : komorebic toggle-float

win + shift + 1 : komorebic toggle-float
win + ctrl + 1 : komorebic toggle-float
win + alt + 1 : komorebic toggle-float

@AJolly
Copy link

AJolly commented Apr 12, 2023

IDK if it helps, but MSFT powertoys fancyzone is capable of overriding the win left/right/up/down hotkeys. (Found this because right now when I use the Win/left etc hot keys, komorebic doesnt seem to notice the window has been moved, so was hoping to use whkdrc to handle that.

@skewballfox
Copy link

if you want to know a bit more about how autohotkey is handling windows keys, I made a regex that should match most of the cases where they are referencing the code (and exclude a ton of non relevant matches) for githubs code search

@bzm3r
Copy link

bzm3r commented Jul 28, 2023

This is quite a difficult problem and a moving goal because Microsoft really don't want users to be able to use MOD_WIN for anything.

image https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-registerhotkey

There are some documented ways to disable certain system MOD_WIN combinations, however they don't seem like they are completely up to date. For example, I just tried setting the NoWinKeys registry entry, and Win+W still brings up the widgets overlay on Windows 11. It does, however, free up other bindings like Win+E, Win+H etc., which can then be bound as expected with whkd, eg. win + e: echo "hello"

Ultimately, you'll have to disable any pre-existing hotkeys registered by Windows yourself before trying to set them with whkd.

I may look into adding a section to the configuration and the parser to allow users to explicitly specify global hotkeys they wish to disable in the future (if UnregisterHotkey even works like that; I'm not sure), but it's very unlikely that this project will ever have a solution where whkd silently unregisters system-level hotkeys without explicit user direction.

Thank you for this explanation. This issue is coming up in using wezterm as well, where a lot of the default keyboard shortcuts use SUPER.

I'm wondering: would using kanata to help us solve this issue?

@fislysandi
Copy link

fislysandi commented Aug 30, 2023

i think you can make a low level hook that intercepts the win key press, instead of trying to "register it"?

it runs as a daemon anyways it should listen to a mapped keypress then perform a command that is mapped to that keypress.

auto hotkey does that and has absolutely no issues with binding anything to a win key.

i wanted to start using tiling window managers and check out your TWM,but this just holds me back.

@LGUG2Z
Copy link
Owner

LGUG2Z commented Aug 30, 2023

You can also use AHK with komorebi, and you're free to open a PR to whkd implementing your suggested approach.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

6 participants