0

I want to get a backtick ` when I type i (Option ⌥+' on my Italian keyboard), and do the same with and ~.

I landed upon this solution which looks great, but I can't find the reference to the correct keys (not so much tilde and backtick, which I can find here, but i and ).

What are the correct codes for these keys? and is there a complete reference?

4
  • Can you post a picture of your keyboard? (Apple used to publish pictures of all layouts, but they're long gone:/)
    – Tetsujin
    Commented May 5, 2023 at 18:00
  • Another way to do what you want is to make a custom Italian layout with ukelele software.sil.org/ukelele Commented May 5, 2023 at 18:41
  • 3
    @Tetsujin the old apple pictures are still available at topteksystem.com/blog/apple-tutorials/… Commented May 5, 2023 at 18:43
  • 1
    @TomGewecke - ah, thank you. Brilliant!! I can add that to the 'change windows' QA which was desperately missing an easy way to add pics.
    – Tetsujin
    Commented May 5, 2023 at 19:07

3 Answers 3

0

The repository you have found yourself is full enough alread, it contains all the possible keys on a keyboard.

But...

Do you even have a key that prints those symbols? I have checked on the awesome link provided by @TomGewecke for the Italian keyboard and saw that there were no key for this, it could only be provided with a keyboard shortcut.

Since the paragraph symbol (¶) and the inverted exclamation mark (¡) can only be obtained by pressing a keyboard shortcut (Option ⌥+ù (Italian keyboard) for the paragraph symbol and Option ⌥+1 for the inverted exclamation mark), there is no keycode for it.

That means there is no way to remap it with hidutil, since hidutil only remaps direct keycodes from the physical keyboard.

See this Apple Support article on how to create custom keyboard shortcuts for more info to help you create another shortcut for ¶ or ¡ if you want.

Additional info

If you wanted to replace a key by another using hidutil, here's how :

Let's take the keyboard key i and replace it by the backtick key. From the repositiory given above, the line giving the keycode for i is :

#define KEY_I 0x0c // Keyboard i and I

It means that the keycode for i is 0x70000000C.

And as you have found already, the keycode for the backtick is 0x700000035 (or 0x35

Meaning that you will have to run (according to the mentioned answer) :

hidutil property --set '{"UserKeyMapping":[{"HIDKeyboardModifierMappingSrc":0x70000000C,"HIDKeyboardModifierMappingDst":0x700000035},{"HIDKeyboardModifierMappingSrc":0x700000035,"HIDKeyboardModifierMappingDst":0x70000000C}]}'

HIDKeyboardModifierMappingSrc (or Src) being the key you want to change and HIDKeyboardModifierMappingDst (or Dst) being the key you want it to be (new key).

Of course you will have to swap both and say that you want ¡ to be changed to backtick and backtick to be changed to ¡. Else the process won't work since one of the two keys would have the other key's functions in addition to its own.

2
  • I would imagine that this is being downvoted because hidutil remaps keys not characters which is what you’re attempting to do here
    – Allan
    Commented May 6, 2023 at 16:31
  • If you have time to test your example replacing letter i with backtik, I think you may find that there is no need to swap both keys as long as you do not mind having two keys that do the same thing. Also that when you swap keys like this, you will also be swapping whatever is on the Option and Option shift levels, in addition to the normal and shift levels. Let us know the results of any experiments you make. Commented May 7, 2023 at 20:48
1

In case it's useful, here is a Ukelele custom layout that should do what you want.

1

And - in case anyone lands here looking for another solution - Karabiner will also solve the problem with this (YMMV - works on my machine):

[
  {
    "description": "Option + accented u is tilde (except in Emacs)",
    "manipulators": [
      {
        "from": {
          "key_code": "backslash",
          "modifiers": {
            "mandatory": [
              "right_option"
            ]
          }
        },
        "to": [
          {
            "key_code": "5",
            "modifiers": [
              "left_option"
            ]
          }
        ],
        "conditions": [
          {
            "type": "frontmost_application_unless",
            "bundle_identifiers": [
              "org.gnu.Emacs"
            ]
          }
        ],
        "type": "basic"
      }
    ]
  },
  {
    "description": "Option + quote is backtick (except in Emacs)",
    "manipulators": [
      {
        "from": {
          "key_code": "hyphen",
          "modifiers": {
            "mandatory": [
              "right_option"
            ]
          }
        },
        "to": [
          {
            "key_code": "non_us_backslash",
            "modifiers": [
              "left_option"
            ]
          }
        ],
        "conditions": [
          {
            "type": "frontmost_application_unless",
            "bundle_identifiers": [
              "org.gnu.Emacs"
            ]
          }
        ],
        "type": "basic"
      }
    ]
  }
]

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .