[HN Gopher] Mac Keyboard with Hidutil
       ___________________________________________________________________
        
       Mac Keyboard with Hidutil
        
       Author : ibobev
       Score  : 99 points
       Date   : 2023-04-13 13:53 UTC (9 hours ago)
        
 (HTM) web link (amitp.blogspot.com)
 (TXT) w3m dump (amitp.blogspot.com)
        
       | ivan888 wrote:
       | I wrote a pretty simple wrapper around this that gives the keys
       | easy names and can store the configuration in a human readable
       | format: https://github.com/ivangreene/keymap
       | 
       | Was unaware of the --matching option at the time, could be an
       | interesting extension but I personally have no need for it
        
         | amitp wrote:
         | Thank you! That looks great.
        
       | BruceEel wrote:
       | Yes, good stuff. Also useful if you have an external PC keyboard
       | and want "INS(ERT)" (0x700000049) to do something sensible...
        
       | teekert wrote:
       | "On the laptop keyboard, some media keys should be function keys
       | but other media keys should stay media keys. When using fn I want
       | to get the other version of the key."
       | 
       | Wow, this is exactly how it should be! Who cares about F1 and F2,
       | let them be brightness controls! A button for "full screen" on
       | F5? No thank you, that should always be "refresh".
       | 
       | Btw, I switch a lot between MacOS and Linux, and my Logitech MX
       | master can be Mac or Windows/Linux. It's maddening that the thing
       | has a "super" _and_ and  "cmd" key. They should have been the
       | same key. Alt and Opt should also have been the same.
        
         | akira2501 wrote:
         | Most laptops I've used have an "Fn Lock" key or mechanism.
         | That's one of the first "out of the box" items I enable. If it
         | lacked one, that'd be a "back in the box" experience for me.
        
           | teekert wrote:
           | Sure, but it does not let you combine brightness controls
           | with F5. It's either or, the functions or the F keys. This
           | let's you mix.
        
       | vvladymyrov wrote:
       | Hiduntil gets job done for remapping keys. The only downside for
       | me is that configuration lost after keyboard was disconnected.
        
         | amitp wrote:
         | I haven't tried this yet but the configuration on
         | https://www.digihunch.com/2022/11/key-mapping-on-external-pc...
         | looks like it will run when the keyboard is connected.
        
       | rgoulter wrote:
       | If you do desire "external keyboards, more than one, slightly
       | different configurations for each one", ... then at that point I
       | think it would be worth considering the benefits of a keyboard
       | where the keyboard firmware itself can be customised.
       | 
       | With the customisable keyboard firmware, your tweaks would remain
       | on the keyboard, & wouldn't need any setup on the OS.
        
         | amitp wrote:
         | Agreed. I do have that, but I _also_ want to use the same
         | keyboard with Mac, Linux, Windows. So far I 've been switching
         | keyboard configurations on the keyboard every time I use a
         | different OS, but I'd like to move that to the OS so that it's
         | automatic.
        
         | kitsunesoba wrote:
         | Config being saved in firmware I think is probably the most
         | underrated boon of enthusiast keyboards. No shaky hacks or
         | badly written background daemons, just plug it in anywhere
         | there's USB and the board acts as expected.
        
           | IggleSniggle wrote:
           | The _downside_ of this approach is that you can't easily do
           | "one size fits all, inclusive of built-in laptop keyboard"
           | mods.
           | 
           | Since my configuration files follow me from computer to
           | computer anyway, it's easier to just manage all the mods in
           | one place and rely on the daemon. If I was doing support
           | though, I would _definitely_ go the firmware route.
        
             | kitsunesoba wrote:
             | Yeah that's fair, and not all daemons are equal --
             | something like Karabiner for instance is manageable, but
             | the software required for the various functions on big name
             | (e.g. Logitech) peripherals can be downright horrendous.
        
       | ink_13 wrote:
       | Interesting, but if I'm understanding this correctly, this can
       | only do straight remaps. I'll stick with Karabiner Elements for
       | its ability to make a key do one thing when tapped (e.g., send a
       | keystroke like ESC) and a different thing when held (e.g., act as
       | a modifier like CTRL).
        
         | SSLy wrote:
         | Do you think I can get something like this for windows or
         | libinput/wayland?
        
           | goosedragons wrote:
           | Kmonad or keyd. Keyd is Linux only but Kmonad is cross
           | platform but harder to configure IMO. Both work everywhere in
           | Linux including TTYs.
        
             | csdvrx wrote:
             | Do either handle the modifier bits when you remap? So that
             | they are not set unless you want to?
        
           | psd1 wrote:
           | PowerToys for Windows has a keyboard remapper. It has nowhere
           | near the power of karabiner, but otoh you don't have to wade
           | through karabiner's config file.
        
         | bt1a wrote:
         | Yeah, Karabiner seems to be unmatched in terms of customization
         | for power users. The main problem with straight key remapping
         | is that you have to deal with the application layer having
         | different keybindings for the same actions, even when you have
         | the appropriate keys swapped. Same for navigating the OS if
         | you're interested in duplicating Windows navigation functions
         | in Mac ( Command+E to open Finder, Command+S for Spotlight
         | Search, Ctrl+Shft+Esc to open Activity Monitor )
         | 
         | I spent a long time creating a giant karabiner config file for
         | myself, but recently an MDM update at my work broke the virtual
         | keyboard driver that Karabiner requires. I haven't figured out
         | a way to install it. I may have to go begging to IT.
        
         | 1-more wrote:
         | Hold-tap is phenomenal in QMK if you want it built in to a
         | keyboard you're building too.
         | 
         | https://qmk.fm
        
           | xiande04 wrote:
           | Karabiner has this. I never could use this. I've tried
           | mapping A to control when held down, but there's always false
           | negatives because I hit control too fast. I've also tried
           | many other keys and different timings, but nothing works for
           | me.
           | 
           | Instead, I map a key to one thing when pressed alone and
           | another when pressed with other keys. Works so much better. I
           | can't live without this now. I really wish QMK had this
           | functionality, but I think it's only available in Karabiner.
        
             | 1-more wrote:
             | Oh yeah I couldn't make it work with letters. Rather I
             | _added_ tap behavior to modifiers. In QMK my command keys
             | are Esc and Enter when tapped, shifts are parentheses (like
             | the space cadet keyboard), controls (outside of A and ;)
             | are single and double quote, Options are braces, and hypers
             | are angle brackets (which I should probably change to
             | brackets since I don 't really write JSX/TSX/HTML much any
             | more)
        
             | 355E3B wrote:
             | QMK does have this, unless I've misunderstood your use
             | case. My QMK keyboard has CAPS mapped to ESC when tapped,
             | CTRL when pressed with other keys. In my keymap.c file,
             | I've put my caps key as just:
             | 
             | MT(MOD_LCTL, KC_ESC)
        
               | seanw444 wrote:
               | I ended up putting arrow keys in my 60%, which shifted
               | the layout (PCB limitations) to where I ended up having
               | to sacrifice my / and ? for a shift key (to fit the empty
               | space). So I ended up having to do something similar.
               | Holding it down and pressing other keys makes it function
               | as a shift. Clicking it by itself yields a period, and
               | clicking it by itself with the other shift does a
               | question mark. QMK is freaking awesome.
               | 
               | RSFT_T(KC_SLSH)
        
       | karmakaze wrote:
       | I have a script I use with Starcraft2 (on Mac I should know
       | better..)
       | 
       | hidutil property --set '{ "UserKeyMapping": [{
       | "HIDKeyboardModifierMappingSrc": 0x70000002B,
       | "HIDKeyboardModifierMappingDst": 0x7000000E1 }, {
       | "HIDKeyboardModifierMappingSrc": 0x700000039,
       | "HIDKeyboardModifierMappingDst": 0x70000002B }, {
       | "HIDKeyboardModifierMappingSrc": 0x7000000E1,
       | "HIDKeyboardModifierMappingDst": 0x7000000E2 }] }'
       | 
       | It remaps tab->L.shift, capslock->tab, L.shift->L.alt Why? Using
       | TheCoreLite, so I can hit tab/caps/shift labelled keys with pinky
       | and cmd with thumb and reach a good number of hotkeys including
       | function keys.
       | 
       | On Windows, the PowerToys keyboard manager can do the same with a
       | nice config UI.
        
         | pixelbath wrote:
         | Oh, man, thanks for this. I've been lamenting that Cmd is
         | essentially dead without remapping it, and this is the last
         | blocker for me adopting TheCore.
        
         | csdvrx wrote:
         | On Windows, you use AHK to do that and way more. You know about
         | Caps being Esc alone and Control when chorded?
         | 
         | Likewise, AHK can turn the Alt keys in Home/End when pressed
         | alone, and the Shift keys in PageUp/PageDown.
         | 
         | One handed Alt-PageUp on the left hand side of the keyboard
         | becomes pressing and holding the left Alt then pressing and
         | releasing the left Shift.
        
       | mproud wrote:
       | Not to be confused with `hdiutil`.
        
       | ris58h wrote:
       | It should have 2019 in the title.
        
         | amitp wrote:
         | It's a blog post from yesterday.
        
           | ris58h wrote:
           | You are right. I confused it with a linked blog post.
        
       | hacliff wrote:
       | for the colemak users http://homeowmorphism.com/2017/05/27/Remap-
       | CapsLock-Backspac...
        
       | fabiospampinato wrote:
       | I wish you could get an Hyper key with built-in utilities without
       | needing to install anything else. Unfortunately hidutil can't map
       | multiple keys to a single key.
        
       | nammi wrote:
       | I think Karabiner(-Elements) is way more popular and probably
       | more flexible, but I've had a lot of success with Ukelele for 6-7
       | years. I exported one layout and just copy it to each new
       | macbook. Specifically it lets me set `option` as a dead key so I
       | can have `opt+i`, `opt+j`, etc... shortcuts in editors.
       | 
       | https://software.sil.org/ukelele/
        
         | kps wrote:
         | The Mac keyboard layout system is good; it's basically a tree
         | of states, so it's both simple and capable. Ukelele is a decent
         | layout editor; the only down side I recall is that it's not
         | easy to create chains analogous to X11 Compose. Editing or
         | generating keyboard layout XML directly is also possible.
         | 
         | Karabiner and hidutil are at a lower level; they modify the key
         | codes that are the input to layout.
        
         | ris58h wrote:
         | It is more flexible but it's a bloatware. I had to spend some
         | time to uninstall it completely.
         | 
         | https://karabiner-elements.pqrs.org/docs/manual/operation/un...
        
       | alana314 wrote:
       | I map my right option key to ctrl, because I use ctrl + arrows
       | way more than option
        
       ___________________________________________________________________
       (page generated 2023-04-13 23:01 UTC)