Overview of suggestion
I still think that the best way to proceed would be to use the input-decode-map. This is an elaboration of Option 3 detailed here https://emacs.stackexchange.com/a/73299/31220.
Quick Suggestion for Experimentaion
Unlike my Debian, your Mac recognizes s- and M- keys.
So, start with this
(define-key input-decode-map (kbd "s-x") (kbd "M-x"))
(define-key input-decode-map (kbd "M-x") (kbd "s-x"))
Now do Command+x and Option+x, do they get swapped. If yes, it is just a matter of writing some loop to install the input-decode-map all other keys that Emacs sees.
Above paragraph means that, instead of saying whenever I see super convert it to M, you say whenever I see s-x convert it to a M-x, whenever I see s-a, convert it to M-a etc.
That is, you go on an case-by-case basis, introducing new translations as you go along. This is the point made in Mappings needed to use cmd as ctrl on kitty+macos, where the user uses a ruby script to generate the maps. In our case, we will be using an Emacs Lisp loop ot generate the translation tables, and it install it in one of the translation keymaps (most likely input-decode-map).
Answer these questions for a ready solution to your problem
Answer the following questions, and I will turn the suggestion below in to a readily-usable solution.
Question Set 1
- What does
Emacs report when you do C-h k Command+x?
- What does
Emacs report when you do C-h k Option+x?
(To answer, Copy paste what you see on *Help* buffer for above questions)
Question Set 2
- In
*scratch* buffer, do C-q Command+x. What do you see?
- In
*scratch* buffer, do C-q Option+x. What do you see?
To answer, do one of the following
- share a screenshot of
scratch buffer after doing above operations
- Do some postmortem analysis of
Emacs and kitty behaviours as seen in the next section, where I analyze the behaviour of LeftWinKey+x on Debian/Windows keyboard.
No access to Mac on my end; so unable to dig deeper
I don't have access to Mac machines. This means,
- I don't have keys marked
Command or Optoin.
- I can't experiment, and delve deep in to what
kitty is sending, and Emacs is doing on a Mac. At the best, I can make only a reasonable guess based on what you share with me.
(As I already shared with you, I don't have access to Mac machines, and this prevents me from experimentaion, and doing reasonable dedcuction from observed behaviours. So, I need to see what happens the Macs)
An attempt at reconciling what Emacs sees and what kitty sends --- A postmotem of observed behaviour of LeftWinKey+x on emacs -Q -nw running on Dell Windows Laptop
(This is for those interested in Debian, where Emacs running within kitty doesn't recognize LeftWinKey+x as s-x)
LeftWinKey+x is NOT recognized
- When in
*scratch* buffer, C-h k LeftWinKey+x reports M-[ 1 2 0 is undefined in *Messages* buffer, and the ;9u is inserted in to *scratch* buffer. (There is a brief way momemt where ESC blah blah flashes in the echo area. This message doesn't end up in the *Messages* buffer)
- While in
*scratch* buffer, doing C-q LeftWinKey+x inserts the encircled "raw" string in the below image.
The circled portion in below image, is the raw code inserted with C-q LeftWinKey+x.

The sexp in the above image is equivalent to
(define-key input-decode-map (kbd "ESC [ 1 2 0 ; 9 u") (kbd "s-x"))
To decode the "raw string" seen in the above image, do C-u C-x = on
each component part. The cryptic first part is ESC [ or M-[.
| Unicode Name |
buffer code |
display |
| ESCAPE |
#x1B |
terminal code #x1B |
| LEFT SQUARE BRACKET |
#x5B |
terminal code #x5B |
| x |
120, #x78 |
terminal code #x78 |
The raw string seen by Emacs is equivalent to the first form of kitty sequence
Kitty-syntax |
CSI |
number |
; |
modifiers |
u |
| Component Parts |
0x1b 0x5b |
120 |
; |
9 |
u |
Emacs-syntax |
ESC |
x |
; |
super |
|
Reproduction of kitty-'s Keyboard Protocol
Reproduced from kitty Keyboard Protocol
| S.No |
Kitty Syntax |
Key |
| 1 |
CSI number ; modifiers [u~] |
|
| 2 |
CSI 1; modifiers [ABCDEFHPQRS] |
|
| 3 |
0x0d - |
Enter |
| 4 |
0x7f or 0x08 |
Backspace |
| 5 |
0x09 - |
Tab |
(CSI is the bytes 0x1b 0x5b)
Encoding of Modifier keys in Kitty
| Modifier |
Value (in binary format ) |
Value (Decimal) |
| shift |
0b1 |
(1) |
| alt |
0b10 |
(2) |
| ctrl |
0b100 |
(4) |
| super |
0b1000 |
(8) |
| hyper |
0b10000 |
(16) |
| meta |
0b100000 |
(32) |
| caps_lock |
0b1000000 |
(64) |
| num_lock |
0b10000000 |
(128) |
In the escape code, the modifier value is encoded as a decimal number which is 1 + actual modifiers.
For example,
Example of how to arrive at decimal value of Modifiers for use with Kitty
| Modifier |
Decimal |
| shift |
1 + 1 = 2 |
| ctrl+shift |
1 + 0b101 = 6 |
| No modifier |
1 |