Skip to content

feat: Add keymap import and export#171

Open
max-hill-4 wants to merge 2 commits into
zmkfirmware:mainfrom
max-hill-4:add-keymap-import-export
Open

feat: Add keymap import and export#171
max-hill-4 wants to merge 2 commits into
zmkfirmware:mainfrom
max-hill-4:add-keymap-import-export

Conversation

@max-hill-4

Copy link
Copy Markdown

Summary

  • Adds an Export Keymap button (download icon) to the header toolbar that saves the current keymap as a .keymap devicetree file with column-aligned bindings
  • Adds an Import Keymap button (upload icon) that loads a .keymap file, parses the devicetree syntax, resolves ZMK keycode names to HID usage codes, and applies bindings to the connected device via RPC
  • New keymap-parser.ts utility for parsing .keymap files with support for standard ZMK keycodes, behavior names, and layer definitions

This addresses the "Importing and exporting keymaps" item on the planned features list.

Test plan

  • Connect a ZMK keyboard and verify Export downloads a valid .keymap file
  • Verify exported file contains correct behavior names and keycode parameters
  • Import a .keymap file and verify bindings are applied to the device
  • Verify Import/Export buttons are disabled when no device is connected

Adds export (download) and import (upload) buttons to the app header
toolbar, allowing users to save their keymap as a .keymap devicetree
file and load one back onto the device.

Export generates a formatted .keymap file with column-aligned bindings.
Import parses .keymap files, resolves ZMK keycode names to HID usage
codes, and applies bindings to the connected device via RPC.
@netlify

netlify Bot commented Apr 16, 2026

Copy link
Copy Markdown

Deploy Preview for zmk-studio ready!

Name Link
🔨 Latest commit 8ffa859
🔍 Latest deploy log https://app.netlify.com/projects/zmk-studio/deploys/69ff5b274c86f40008340504
😎 Deploy Preview https://deploy-preview-171.preview.zmk.studio
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@CaioCosta

Copy link
Copy Markdown

Hey mate! I was just testing you branch because I'm in dire need of this feature and found out that the icons are reversed. Currently the icon with the arrow going out is Import and the one with the arrow coming in is Export. It should be the other way around.

Other than that THANK YOU for making import and export finally possible on ZMK. You're a lifesaver.

Replace icon-only Download and Upload buttons with text labels for
better clarity and accessibility in the keymap import/export toolbar.

Co-Authored-By: Claude <noreply@anthropic.com>
@max-hill-4 max-hill-4 force-pushed the add-keymap-import-export branch from 8886fe0 to 8ffa859 Compare May 9, 2026 16:04
@max-hill-4

Copy link
Copy Markdown
Author

Hey mate! I was just testing you branch because I'm in dire need of this feature and found out that the icons are reversed. Currently the icon with the arrow going out is Import and the one with the arrow coming in is Export. It should be the other way around.

Other than that THANK YOU for making import and export finally possible on ZMK. You're a lifesaver.

I think it is tricky to represent with icons, as the Export Keymap was a keymap 'download' so it had the download icon, to reduce any confusion; changed to Download/Upload text buttons.

numachang added a commit to numachang/zmk-studio-tweaks that referenced this pull request May 22, 2026
…eady matches

PR zmkfirmware#171's import unconditionally called setLayerBinding for every
binding parsed out of the file. Even when the file value was
identical to the device's current value (e.g. the user re-imported
their own export with no edits), the firmware still flipped its
"unsaved changes" flag because *some* setLayerBinding had been
called. Save then appeared armed for a no-op flash write, which is
both confusing and bad for flash longevity.

Diff before calling: fetch keymap.layers once, then per position
compare {behaviorId, param1, param2} against the parsed binding.
Skip the RPC when they match and count it as `unchanged`.

Reword the toast accordingly:

  - Everything matched:   "<file> already matches the device. No
                          changes needed." (info)
  - Some real updates:    "Updated N binding(s) from <file> (M
                          already matched)." with the persist
                          reminder.
  - Partial / rejected:   "Updated N (M already matched), skipped X,
                          rejected Y. …"

The `applied` counter is renamed `updated` to match the new
semantics. preserved / skipped / failed handling is unchanged.

Co-Authored-By: Claude <noreply@anthropic.com>
numachang added a commit to numachang/zmk-studio-tweaks that referenced this pull request May 22, 2026
feat: Reliable keymap import/export (refines upstream PR zmkfirmware#171)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants