Per-keyboard automatic input source switching for macOS.
Klef is a macOS menu bar app that automatically switches your keyboard layout based on which physical keyboard you're typing on. Map each detected keyboard once — internal AZERTY, external QWERTY, Bluetooth French-PC — and Klef takes care of switching the layout when you change keyboards.
macOS has no native per-device input source switching. The built-in "Automatically switch to a document's input source" works per-app, not per-keyboard. The only existing CLI tool (autokbisw) has no GUI and known device-classification bugs. Klef closes that gap.
Status: V0.3. Fully functional menu bar app. Builds are not yet signed with a Developer ID or notarized — see Installing for the extra step macOS requires on first launch.
Download the latest Klef-x.y.z.dmg from the
releases page, open it, and
drag Klef to Applications.
Because the build is ad-hoc signed rather than notarized, macOS will refuse to open it the first time with a message about being unable to verify the developer. To approve it:
- Try to open Klef once and dismiss the warning.
- Open System Settings → Privacy & Security.
- Scroll to the Security section — there is now an Open Anyway button for Klef. Click it and confirm.
Only needed once. On macOS 15 (Sequoia) and later, the old Control-click → Open shortcut no longer bypasses Gatekeeper; System Settings is the only route.
You can verify your download against the .sha256 file published alongside each
release:
shasum -a 256 -c Klef-0.3.0.dmg.sha256Klef needs Input Monitoring access to know which keyboard an event came from. macOS should prompt on first launch. If no prompt appears:
- Open System Settings → Privacy & Security → Input Monitoring.
- Add and enable Klef.
- Relaunch Klef.
Klef requests Input Monitoring, the same permission a keylogger would need, so here is exactly what it does with it — every claim below is checkable against the source.
- Keystroke content is never read. For each HID event Klef reads only the
usage page and usage code to classify the key into a coarse bucket
(
letter,digit,modifier,arrow, …) — seeHIDUsageClass.classify. The specific key is never stored, logged, or acted on. What actually drives a switch is which device the event came from, not what was typed. - Klef never seizes the input stream.
IOHIDManageris opened withkIOHIDOptionsTypeNone(shared monitoring), not exclusive capture — seeHIDKeyboardManager. - One outbound request on its own, and you can switch it off. No telemetry,
no analytics, no crash reporting. The only network call Klef makes without
being asked is an unauthenticated
GETtoapi.github.com/repos/JohanDevl/Klef/releases/latest, at most once a day, to see whether a newer release exists — seeUpdateChecker. It sends no request body and no identifiers beyond the IP address andUser-Agentthat any HTTP client sends. Turn it off in Settings and Klef makes no network requests unless you click a button that asks for one. - Nothing is downloaded or installed unless you click Install Update. The
update check only reports that a release exists. If you then choose to
install it, Klef downloads that release's disk image from
github.com/JohanDevl/Klef/releases, checks it against the size and SHA-256 GitHub publishes for it, and replaces its own app bundle; the previous version goes to the Trash — seeUpdateInstaller. That checksum proves the download is the published file, not that the release is genuine: it is the same trust as downloading the DMG yourself. Because Klef fetches the image itself, macOS does not quarantine it, so an in-app update skips the Gatekeeper prompt a browser download would get. Apart from an install — a temporary download, the bundle swap, the old version in the Trash — Klef never writes outside its own preferences. - No third-party dependencies. Everything Klef links ships with macOS.
IOKitandCarbonare named explicitly inPackage.swift; the rest (SwiftUI, AppKit,ServiceManagementfor launch at login, …) comes from plain imports of Apple system frameworks.otool -L Klef.app/Contents/MacOS/klefshows the full list. - Everything stays local. Your keyboard-to-layout mappings live in
UserDefaultsunderklef.mappings.v1. Nothing leaves your Mac. - Logs are redacted. Device names are passed through
Log.redactSerialLike, which strips trailing serial-looking tokens before anything is written.
Klef is MIT-licensed and the whole thing is a few thousand lines of Swift with no third-party dependencies. If you'd rather not trust a downloaded binary, build it yourself.
- Detect every connected keyboard (built-in, USB, Bluetooth) and surface them in a menu bar UI.
- Map each keyboard to one input source from the system's enabled list.
- Switch the active input source automatically on keyboard change, with the lowest practical latency.
- Polished onboarding for the required Input Monitoring permission.
- Signed and notarized DMG, macOS 13 (Ventura) and later.
- Per-app or per-website switching (use Input Source Pro for that).
- Key remapping or modifier customization (use Karabiner-Elements).
- CJKV input methods.
- Mac App Store distribution (the sandbox blocks
IOHIDManager).
- Click the keyboard icon in the menu bar.
- Select Open Klef Settings….
- For each detected keyboard, pick an input source from the dropdown.
Mappings persist across relaunches. Keyboards you have seen before appear in a "Known, not connected" section even when unplugged.
Klef checks GitHub once a day for a newer release and, if it finds one, shows it in the menu and in Settings. It never downloads or installs anything by itself. Click Install Update in Settings and Klef downloads the release, verifies it, replaces itself and reopens; Release Notes opens the release page if you would rather install by hand. Use Check for Updates… in the menu to look right away, or turn the daily check off entirely in Settings.
In-app install needs Klef to live somewhere it can write to — the Applications folder, in practice. Klef refuses to update a copy still running from its download location and tells you to move it first.
Re-grant Input Monitoring after every update. macOS ties the permission to the app binary's code signature hash, and because Klef's builds are ad-hoc signed rather than Developer ID signed, that hash changes with every release. After installing a new version, Klef will appear to run normally but switch nothing until you re-enable it under System Settings → Privacy & Security → Input Monitoring. After an in-app update Klef opens that pane for you; the menu bar icon also shows a warning badge whenever this has happened. Developer ID signing fixes it permanently and is planned for V1.0.
- macOS 13 (Ventura) or later
- Xcode 15+ (the Command Line Tools alone are not enough — SwiftUI's macro plugins ship inside Xcode)
swift build -c release && ./scripts/bundle-app.sh --force && open Klef.appbundle-app.sh assembles Klef.app, stamps the version, and ad-hoc signs it.
Drop -c release for a faster debug build.
To produce a DMG the way CI does:
./scripts/make-dmg.sh # → dist/Klef-<version>.dmgNote: after each rebuild the binary's code-sign hash changes, so macOS may invalidate the Input Monitoring grant and silently stop switching. Re-grant in System Settings → Privacy & Security → Input Monitoring when that happens.
version.txt is the single source of truth for the marketing version and is
maintained automatically by release-please. Resources/Info.plist carries
placeholders that bundle-app.sh substitutes at bundle time — the build number
comes from the commit count. Don't hand-edit either version key.
Resources/Klef.icns and Resources/logo/klef-icon.png are committed. Only
re-run this after changing the artwork in Resources/logo/:
./scripts/make-icon.shSwift 5.10+, SwiftUI for settings, AppKit NSStatusItem for the menu bar,
IOHIDManager for keyboard detection, Carbon TIS for input source switching.
No third-party dependencies.
scripts/install-launch-agent.sh and uninstall-launch-agent.sh are left over
from the pre-menu-bar V0.2 dogfood path. They still work if you want to run the
raw binary as a background daemon, but the .app bundle is the supported route.
- First-keystroke race. A single character key-down as the very first input on a freshly-promoted keyboard can still race the switch — a measured improvement, not a fix.
- Secure Input. When
IsSecureEventInputEnabled()is true (password fields, some Terminal contexts), the switch is attempted but may silently fail. Logged as a warning. - Two identical keyboards on the same Mac are indistinguishable — identity
is
locationID-based. - Builds are ad-hoc signed only. Developer ID signing and notarization are planned for V1.0; the release pipeline is already wired for them. Until then, every update revokes the Input Monitoring grant (see Updates), which is also why Klef only installs an update when you ask it to — a silent background update would leave a dead app behind.
- No first-launch onboarding. The Settings window opens the Input Monitoring pane directly when permission is denied, but there is no welcome flow. V1.0.
See CONTRIBUTING.md. Commits follow Conventional Commits — that's what drives the changelog and the version bump.
MIT.