From fb342e6e8cc9fc71efa7ff6dea515150539d0e01 Mon Sep 17 00:00:00 2001 From: Verity <954902+verityj@users.noreply.github.com> Date: Wed, 28 Jun 2023 14:03:31 -0400 Subject: [PATCH] Eject key - modify it! The super simple way --- _posts/2023-06-17-eject.md | 62 +++++++++++++++++++++----------------- 1 file changed, 34 insertions(+), 28 deletions(-) diff --git a/_posts/2023-06-17-eject.md b/_posts/2023-06-17-eject.md index 2711b46..b4d96f2 100644 --- a/_posts/2023-06-17-eject.md +++ b/_posts/2023-06-17-eject.md @@ -14,25 +14,25 @@ Here is a command that uses `hidutil` command. Takes in the eject key as source ``` $ hidutil property --set '{"UserKeyMapping": - [{"HIDKeyboardModifierMappingSrc":0xC000000b8, - "HIDKeyboardModifierMappingDst":0x70000004c}] + [{"HIDKeyboardModifierMappingSrc":0xC000000b8, + "HIDKeyboardModifierMappingDst":0x70000004c}] }' - # Output of the above command: + # Output of the above command: UserKeyMapping:( - { - HIDKeyboardModifierMappingDst = 30064771148; - HIDKeyboardModifierMappingSrc = 51539607736; - } + { + HIDKeyboardModifierMappingDst = 30064771148; + HIDKeyboardModifierMappingSrc = 51539607736; + } ) ``` ``` $ hidutil property --get "UserKeyMapping" - # shows existing user key maps + # shows existing user key maps ( - { - HIDKeyboardModifierMappingDst = 30064771148; - HIDKeyboardModifierMappingSrc = 51539607736; - } + { + HIDKeyboardModifierMappingDst = 30064771148; + HIDKeyboardModifierMappingSrc = 51539607736; + } ) ``` @@ -44,8 +44,8 @@ $ hidutil property --set '{"UserKeyMapping":[null]}' UserKeyMapping:( ) $ hidutil property --get "UserKeyMapping" - # shows existing user key maps - # now there are none: + # shows existing user key maps + # now there are none: ( ) ``` @@ -73,7 +73,7 @@ If you notice, I am using **two** key bindings. The first source is the _eject_ Once you create the above file, _System Settings_ may show a notification that _hidutil_ has been added to your _Login Items_. That makes sense, this will be executed after you log in. For example, these key changes will not be active on the log in screen (unless you put this file at the system level, not user). - + Reboot to see that all is functioning as intended. Or launch the service manually: @@ -93,14 +93,14 @@ After a reboot or service start, check that the keys are indeed mapped: ``` $ hidutil property --get "UserKeyMapping" ( - { - HIDKeyboardModifierMappingDst = 30064771148; - HIDKeyboardModifierMappingSrc = 51539607736; - }, - { - HIDKeyboardModifierMappingDst = 30064771148; - HIDKeyboardModifierMappingSrc = 30064771302; - } + { + HIDKeyboardModifierMappingDst = 30064771148; + HIDKeyboardModifierMappingSrc = 51539607736; + }, + { + HIDKeyboardModifierMappingDst = 30064771148; + HIDKeyboardModifierMappingSrc = 30064771302; + } ) ``` @@ -114,11 +114,11 @@ We can expand on this idea of identifying a keyboard key by its code in order to ``` for ((i=1;i<=128;++i)); do - printf '0x7000000%0x\n' "$i" - printf '{"UserKeyMapping":[{"HIDKeyboardModifierMappingSrc":0x7000000%0x,"HIDKeyboardModifierMappingDst":0x70000000a}]}' "$i" | - xargs -0 hidutil property --set >/dev/null - read -p "Type some stuff: " - hidutil property --set '{"UserKeyMapping":[{}]}' >/dev/null + printf '0x7000000%0x\n' "$i" + printf '{"UserKeyMapping":[{"HIDKeyboardModifierMappingSrc":0x7000000%0x,"HIDKeyboardModifierMappingDst":0x70000000a}]}' "$i" | + xargs -0 hidutil property --set >/dev/null + read -p "Type some stuff: " + hidutil property --set '{"UserKeyMapping":[{}]}' >/dev/null done ``` @@ -138,3 +138,9 @@ I also came across a blog post which goes into the benefit of not relying on cus [^4]: Remapping keys - Apple developer [technical note TN2450](https://developer.apple.com/library/archive/technotes/tn2450/_index.html). [^5]: [Script source](https://apple.stackexchange.com/a/349440) in a discussion thread. [^6]: Rakhesh's [blog post](https://rakhesh.com/mac/using-hidutil-to-map-macos-keyboard-keys/) + +## Say Hi! + + + +