# KeyHarbor 1.1.0

A native SwiftUI macOS keyboard remapper for reported keyboard and media events. The downloadable package is **Apple Silicon, macOS 13+**, locally ad-hoc signed and **not notarized**. No subscription, network service, kernel extension, HID driver, or telemetry.

## Install and run

1. Unzip `KeyHarbor-1.1.0-macOS-arm64.zip`, move KeyHarbor.app to `/Applications`, and open it. This is a personal, unnotarized build; macOS may require you to review it in System Settings → Privacy & Security. Do not disable Gatekeeper globally.
2. Open **권한 설정 (Setup)**. Grant Accessibility and Input Monitoring to **KeyHarbor** in System Settings → Privacy & Security. Screen Recording is needed only for screenshot actions. The app never silently grants itself permissions. Restart it if macOS requests that; click **Retry engine** afterward.
3. In **환경설정 (Settings)**, scan monitors, explicitly choose a DDC-readable target, choose installed English and Korean input sources, and set volume and brightness steps.
4. **규칙 추가 → 키 기록 / 선택 → press a key or choose from the onscreen keyboard → 이 키로 설정 → choose an action → 사용**. Recording times out after 15 seconds; Escape cancels. A sheet previews the draft and applies it only after explicit confirmation. Without event-tap permission, a local NSEvent monitor records while the app is focused. An onscreen keyboard can select ordinary keys, left/right modifier taps, media keys, and modifier combinations without any recording permission. Manual selection does not make firmware-only keys available. Changing the trigger disables the rule until reviewed. Starter rules begin disabled; only the unambiguous Right Option trigger is prefilled.
5. Keep the app running. When permissions are missing, the first screen opens Setup. Closing the window leaves its menu-bar control available. **Control + Shift + Command + Escape** pauses globally. Menu-bar Pause and Quit are also available. 환경설정 (Settings) → 자동 실행 (Startup) can register the app as a macOS login item using SMAppService. Install it in Applications first. The switch reports the actual OS state, including approval required; disable it here or in General → Login Items. It reopens the saved profile and starts the engine when permissions are available. Login registration is opt-in for downloaded copies.

Settings and profiles save atomically at `~/Library/Application Support/KeyHarbor/profiles.json`. A malformed file is preserved under a dated name before starting a fresh profile. Use Settings to rename/create/delete profiles and export/import JSON. Imports add new profiles with disabled rules; they do not replace current rules or settings.

## Actions

- Default-output volume up/down with 0.1–10% GUI steps (1% default), Core Audio mute. Fixed HDMI/USB DAC outputs can reject software volume; errors appear in the status bar.
- Hardware brightness up/down on an explicitly selected external display using bundled m1ddc. Steps are a percentage of that monitor's reported maximum; a minimum of one VCP unit is used. Reads and writes run off the keyboard callback with a timeout. Rapid repeated brightness requests are dropped while a request is busy rather than queued indefinitely.
- Full screen or interactive selected area to clipboard through Apple's `/usr/sbin/screencapture -c`. Escape cancels an interactive capture. macOS determines multi-display behavior. No image is saved by KeyHarbor.
- Configurable English/Korean input-source toggle using Carbon TIS; install both sources in Keyboard → Text Input first. Left/right Command, Option, Shift, and Control can be recorded as modifier-only triggers. Tap and release the modifier alone; mappings fire on release and preserve normal chords. Right Option/Alt → input toggle is provided as a starter.
- Copy, paste, cut, undo/redo, select all, Spotlight, default Mission Control/Show Desktop shortcuts, media playback/track controls, and a recorded custom keyboard shortcut. Custom target must be a keyboard key/chord. System shortcut assignments and app behavior still apply.

## Hardware and macOS limits

This is a **global event-tap remapper**, not a per-device HID remapper: rules apply to the K380 and all other keyboards that produce the same events. The GUI discloses this. Device-specific rules would require a separate HID/virtual keyboard architecture.

K380 Fn is often processed by keyboard firmware or Logitech software. A physical Fn combination may emit a normal F-key, a consumer/media event, an already transformed shortcut, or nothing. KeyHarbor supports the resulting events and the macOS Fn modifier when reported. It cannot intercept proprietary firmware-only Fn, Easy-Switch, power, or Touch ID. It does not reprogram K380 firmware. Logitech's documented function-key preference in Options/Options+ can change which events are delivered. Use **Diagnostics** to observe actual codes; nothing appearing means the event is unavailable at this tap. A missing standalone Fn event is not fixed by giving more app permissions.

The Apple Silicon DDC backend uses private IOAVService/CoreDisplay interfaces via m1ddc. DDC/CI must be enabled in the Dell/other monitor's own menu. Monitor model, cable, adapters, port, HDR, firmware, and macOS can affect support. A successful read is **not** proof that a write will work; status messages show readback after writes. Disconnected targets never silently switch to another monitor. A saved target is probed automatically when the engine starts. Rescan after reconnecting, waking, or changing displays. Intel and DisplayLink do not work with this backend. There is **no automatic software dimming**. If unavailable, use the monitor menu or a compatible utility such as BetterDisplay. Other actions can still work.

Duplicate enabled triggers in the active profile block every conflicting rule. Injected events carry a marker and bypass remapping, preventing loops even across multiple rules. Key-up suppression is tracked after consumed keydowns. Only brightness/volume repeat; other actions are debounced. Event taps automatically re-enable after macOS interruptions. The emergency pause chord is reserved even if a user creates a rule for it.

Secure Input, password fields, system-reserved shortcuts, and another remapper can prevent events or consume them first. Pause overlapping rules in Karabiner, Logi Options, BetterDisplay, or similar utilities. KeyHarbor does not edit those apps. Rebuilding or moving this ad-hoc-signed app can invalidate TCC permissions: remove the old entry and re-add the final app if needed.

The explicit diagnostic monitor logs key codes and modifier flags **in memory only**, with a 150-line limit. It is off at launch, never saved or transmitted, and should not be used while entering passwords.

## Build and verify

Apple Command Line Tools with Swift 5.9+ and a macOS SDK are sufficient for the release app:

```sh
./scripts/build.sh
open dist/KeyHarbor.app
./scripts/test.sh
```

`--self-test` runs 32 offline assertions against actual model and event-engine code. It creates local synthetic event objects, but does not create an event tap, post keys, change devices, or capture the screen. Run it in a normal GUI login session: the sandbox can block NSEvent construction. XCTest sources are also included for `swift test` on a machine with full Xcode; this environment only has Command Line Tools, so the executable checks are the verified path.

The build packages the helper and its MIT license, verifies the nested ad-hoc signatures, and produces a ZIP in `dist/`. On Intel, the app can be built locally for non-DDC actions; this release has not been built/tested for Intel and the published ZIP is arm64 only. For distribution with fewer trust prompts, set `SIGN_IDENTITY` to a Developer ID Application certificate and use Apple's normal hardened-runtime/notarization workflow. This release is not notarized or App Store sandboxed.

See [docs/VERIFICATION.md](docs/VERIFICATION.md) for tested vs. untested behavior. No capabilities should be inferred from screenshots alone.

## Source layout and third-party code

`KeyHarborCore/Models.swift`: schema, validation, matching/conflict policy. `EventEngine.swift`: session event tap, recording, left/right modifier taps, media decoding, recursion protection. `SystemActions.swift`: Core Audio, TIS, clipboard screenshots and output shortcuts. `DisplayController.swift`: bounded asynchronous helper execution and DDC probes. `Views.swift`: native editor, setup, settings and in-memory diagnostics.

`Vendor/m1ddc` is MIT-licensed code by István Tóth and contributors, pinned at `04d949794102eb8df01ad3681afff6464a3eede2`; see its LICENSE. It is bundled from source without behavior changes. Upstream: https://github.com/waydabber/m1ddc. Hardware limitations: https://github.com/MonitorControl/MonitorControl. K380 guide: https://support.logi.com/hc/en-us/articles/360024158554-Getting-started-K380-Multi-Device-Bluetooth-Keyboard. Apple event taps: https://developer.apple.com/documentation/coregraphics/cgevent/tapcreate(tap:place:options:eventsofinterest:callback:userinfo:).
