path:
/README.md
6.29 KB | plain
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# dwhkd
A general-purpose Windows hotkey daemon forked from [theSoberSobber/sxhkd-win32](https://github.com/theSoberSobber/sxhkd-win32). It keeps the original `RegisterHotKey`/`WM_HOTKEY` approach, but uses a config file instead of compiled-in bindings. No hotkeys are built in; the original desktop actions are available as optional config commands.
## Configure and build
From an **x64 Visual Studio Developer Command Prompt**, build with `busybox make` (requires [BusyBox for Windows](https://frippery.org/busybox/) on `PATH`). This invokes MSVC `cl.exe` and `link.exe`; no MSYS, Cygwin, MinGW, or Rust is needed. Run `busybox make test` for parser/plugin checks, and `busybox make test-vd` for live virtual-desktop COM checks on a supported Windows 11 desktop. Copy [dwhkdrc.example](dwhkdrc.example) to `%APPDATA%\dwhkd\dwhkdrc` (create the directory), or run `dwhkd.exe -c C:\path\to\dwhkdrc`. A valid config is required; restart after edits.
The format is inspired by [baskerville/shkd](https://github.com/baskerville/shkd): a hotkey line followed by one or more indented plugin, built-in, or Windows `cmd.exe /C` commands. Commands run in order; a nonzero result stops the remaining commands. Separate case-insensitive names with spaces or `+`; `#` lines are comments. The last definition of a hotkey wins. Supported modifiers: `alt`, `ctrl`/`control`, `shift`, `meta`/`super`/`win`. Supported keys: letters, digits, F1–F24, `return`/`enter`, `tab`, `space`, `escape`, `backspace`, `delete`, `insert`, `home`, `end`, `pageup`, `pagedown`, arrows, `printscreen`, `pause`, named punctuation (`minus`, `equal`, `comma`, `period`, `slash`, `semicolon`, `apostrophe`, `backslash`, `bracketleft`, `bracketright`, `grave`), and `=N` (Windows virtual-key code 1–255, **not** a Linux keycode).
Built-in actions: `:toggle-explorer`, `:close-window`, `:force-close-window`, `:quit`, and the debug-only `:test`. Virtual-desktop actions live in the [C plugin](plugins/vd/README.md): `:vd goto-desktop N`, `:vd move-to-desktop N`, `:vd pin-app`, `:vd unpin-app`, and `:vd app-pin-status`. A [manual test config](dwhkdrc.manual) binds app pinning and desktop switching for live checks. Desktop numbers are 1–10 (`0` also means 10). `busybox make` builds `plugins/vd/plugin.dll`; when distributing it, include the original [MIT notice](libs/virtualdesktopaccessor/LICENSE.txt).
## Plugins
A config command `:name action arguments` loads `plugins/name/plugin.dll` next to the executable. The host loads each **referenced** DLL once at startup, checks `sxhkd_plugin_abi()` against version 1, then calls `sxhkd_plugin_invoke(const char *action, const char *arguments)` on each matching hotkey. The function returns **0 on success**, nonzero on failure. The plugin parses the text arguments and obtains runtime values (such as `GetForegroundWindow()`) itself. It can export any action names it chooses: **adding actions or plugins does not require recompiling the host**. See [`plugin.h`](plugin.h) and the [working test plugin](tests/plugin_smoke.c) (`BUILD_PLUGIN` branch) for the C ABI: export `int sxhkd_plugin_abi(void)` returning `SXHKD_PLUGIN_ABI`, and `int sxhkd_plugin_invoke(const char *, const char *)`. Build your DLL as `plugins/<name>/plugin.dll`; no host rebuild is needed. The `sxhkd_plugin_*` export names remain unchanged for plugin ABI compatibility despite the project rename. Plugin names and action names are single whitespace-delimited tokens containing only letters, digits, hyphens, and underscores; the remaining argument text may contain spaces. No paths or arbitrary DLLs are accepted. A missing or incompatible referenced plugin stops startup; only load DLLs you trust. The host still owns the few built-in actions listed above.
### Notes for plugin authors
Return **0 for success**, nonzero for failure. A hotkey can list multiple indented commands; the host calls each in order and stops when one fails. Plugin actions should perform their work **without hardcoded message boxes, toasts, or notifications**. Users decide whether and how to show feedback by adding their own notification command after the action:
```text
ctrl + alt + shift + f7
:vd pin-app
your-notifier.exe "App pinned"
```
The notifier runs only if `pin-app` returns 0. Shell commands are launched asynchronously, so only launch success—not the shell command's eventual exit code—controls the next step. `:vd app-pin-status` returns 0 when the foreground app is pinned and nonzero otherwise; it does not show UI. The [manual test config](dwhkdrc.manual) leaves feedback to you.
### Compared with AutoHotkey `DllCall`
Both can run native DLL code **in-process**, without launching an executable for each hotkey. Their formats are **not the same**:
```text
AutoHotkey: DllCall("plugin.dll\MoveWindowToDesktopNumber", "Ptr", hwnd, "Int", 1, "Int")
This config: :vd move-to-desktop 2
```
AutoHotkey names a DLL export and supplies typed argument/value pairs (here an `HWND` pointer and a zero-based desktop index). Our Vim-like `:` means **dispatch a managed command instead of a shell command**: `vd` selects a plugin loaded once at startup, `move-to-desktop` is the plugin's action name, and `2` is passed as text. The plugin obtains the live `HWND`, converts the user-facing number to a zero-based index, and makes the typed call in C. `:` does **not** call an arbitrary DLL export or specify argument types; it is only syntax for selecting a built-in or plugin action. Plugins are native code, **not sandboxed**—the prefix does not make an untrusted DLL safe. See [AutoHotkey's DllCall documentation](https://www.autohotkey.com/docs/v2/lib/DllCall.htm).
shkd's `release` bindings, modes, Linux-only keys, and live reload are not supported. Windows cannot register a shortcut already claimed by another application; registration errors go to stderr. Commands run as your user, so only use config files you trust.
The Windows message-window approach comes from the original sxhkd-win32. [`config.c`](config.c) is an independent Windows parser inspired by [shkd by Bastien Dejean](https://github.com/baskerville/shkd) (© 2012); **no shkd source code is vendored**. The original sxhkd-win32 has no license file: obtain permission before redistributing this fork. The adapted C library keeps the original author's [MIT license and notice](libs/virtualdesktopaccessor/LICENSE.txt) in `libs/virtualdesktopaccessor/`.