LGUG2Z / whkd

A simple hotkey daemon for Windows
MIT License
529 stars 12 forks source link

[FEAT]: allow using non modifier keys as modifiers #28

Closed wis closed 1 year ago

wis commented 1 year ago

Is your feature request related to a problem? Please describe. currently when having ESCAPE + h : komorebic focus left in whkdrc, you get this error on startup:

Error:
   0: invalid key name `ESCAPE`

Location:
   src\main.rs:204

Backtrace omitted. Run with RUST_BACKTRACE=1 environment variable to display it.
Run with RUST_BACKTRACE=full to include source snippets.

Describe the solution you'd like one should be able to use hotkeys such as ESCAPE + h, to leave the modifier hotkeys available for applications.

Describe alternatives you've considered I have been trying to enable this with AHK for a long time but I couldn't, ahk scripting is really non-intuitive and confusing.

Additional context I have the right alt key on my keyboard to the escape key using the registry remapping method, so to the OS it is an escape key not an alt key, this makes using vim more convenient since I can keep my right thumb always on this key. I would like to use this key also as if it is a "Pseudo-"modifier key, when it is pressed in combination with other keys, but it should not act as a modifier key when it is pressed and release by itself, it should press escape when it is released, and not the exact moment it is pressed down.

LGUG2Z commented 1 year ago

whkd doesn't actually implement the hotkey registration logic itself, but calls into another library called windows-hotkeys which handles the hotkey registration, and this library sticks to the modifier keys identified in the Win32 API.

I think it may be worth checking out kanata, which I use alongside whkd.

With kanata, it is possible to set a key (right alt in this case), to act as ESC when tapped, but to act as a modifier that activates a "layer" when held. On this layer, you can set hjkl to obscure keys like F20, F21 etc, so that when you do right alt + h, the key code for F20 gets sent.

Then, you can use F20 in whkd to bind to komorebic focus left etc.

wis commented 1 year ago

Thank you very much, I finally was able to do this, I find kanata's config language hard, and kanata's docs are not as beginner-friendly as I would've liked.

EDIT: do you know if kanata supports configuring it to execute a command on a key or hotkey press? e.gkomorbic focus left? EDIT2: actually, I'd prefer something like this https://github.com/jtroo/kanata/issues/43 the smallest (Komorbic or bspc like) C program I found takes at least 10 millisecond to start on Windows, I would prefer IPC, which does not have this lag. I see your comments on that issue, how did you add this feature to Kanata? EDIT3: I read the design doc and read the output of kanata --help so I realized that there's a -p argument. and I used your simple python TCP client code and got output like yours. thank you. Now I'm looking for a way to send an event to the TCP client that a key was pressed (other than the hacky option of making a whole layer for every key).