amarsyla / hidutil-key-remapping-generator

Simple tool to generate HIDUTIL key remapping configurations for MacOS
https://hidutil-generator.netlify.app/
263 stars 18 forks source link

Stops working randomly, needs a restart #3

Closed Eugleo closed 4 years ago

Eugleo commented 4 years ago

Hey, firstly, thanks for this amazing utility! I'm remapping caps lock to esc and esc to fn, and my ~/Library/LaunchAgents/com.local.KeyRemapping.plist looks thus (verbatim copied from you website):

> cat ~/Library/LaunchAgents/com.local.KeyRemapping.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>com.local.KeyRemapping</string>
    <key>ProgramArguments</key>
    <array>
        <string>/usr/bin/hidutil</string>
        <string>property</string>
        <string>--set</string>
        <string>{"UserKeyMapping":[
            {
              "HIDKeyboardModifierMappingSrc": 0x700000039,
              "HIDKeyboardModifierMappingDst": 0x700000029
            },
            {
              "HIDKeyboardModifierMappingSrc": 0x700000029,
              "HIDKeyboardModifierMappingDst": 0xFF00000003
            }
        ]}</string>
    </array>
    <key>RunAtLoad</key>
    <true/>
</dict>
</plist>

After using my Mac for a while, the remaps stop working; the keys themselves don't do anything (as if they weren't mapped to anything). A restart solves it. Any idea what might be causing it?

System info: MacOS 11 (latest beta), mid 2014 15" retina MBP.

amarsyla commented 4 years ago

@Eugleo Not sure about this. I've been using the config from the tool on a couple of computers for a couple of weeks and I haven't encountered that issue. It could be that another software is modifying the UserKeyMapping configuration. You can view the current config with this command:

hidutil property --get UserKeyMapping

After it stops working, you can use the same command to see if the config actually changes. Since this tool only generates the config for hidutil, I don't think I'll be able to help you debug this issue further as I don't have much knowledge on this topic either. I only use it for a couple of basic remaps on my computers and that's it.

Does this happen with other remaps or only with the fn key? The fn key can be problematic since different keyboards produce different value IDs for it. I could get the fn remap working only for my MacBook keyboard. I couldn't get it to work for external keyboards.

Eugleo commented 4 years ago

Thanks for the response nonetheless! I'll report any potential findings.

Now that I think about it, I was using an external keyboard when the issue happened, but definitely neither the esc->fn nor the caps->esc bindings worked. Since I'm on holiday, I won't have the keyboard with me, so it's going to be easy to test whether it was the keyboard causing these issues.

Eugleo commented 4 years ago

Update: It happened again; it seems it remaps esc->fn, and then cap->esc which transitively ends up being caps->fn. Weird, I'd swear caps was temporarily working as Esc, as intended. Will report further.