Key sequence not sent to the programs - CMD+SHIFT+CTRL

176 views
Skip to first unread message

Chaitanya Kuchimanchi

unread,
Nov 7, 2019, 7:24:23 AM11/7/19
to iterm2-discuss
Hello there,

I'm using karabiner elements and a complex configuration that maps Caps lock to -> "Cmd+Shift+Ctrl" . This is sort of simulating a hyper key so that we can have customised shortcuts without overlapping with other shortcuts

However, while working in terminal (using iterm2 of course and it's fantastic :) ), if I then press, say,  Caps-lock+V (which is nothing but Cmd+Shift+control+V because of the karabiner mapping) i don't see anything happening - I mean no sequence is being sent to the program (either bash/zsh/vim that's running in the terminal) 

To debug this, I used the 'sed -n l' command which prints out the sequences that it got and it just prints nothing.

Can someone please help me how to debug this? If the sequences do get sent, I intend to map them appropriately in my vim/bash but the problem here is there are no keystrokes being sent. Please correct me if my thinking is wrong? 

Thanks in advance!

George Nachman

unread,
Nov 9, 2019, 4:57:28 PM11/9/19
to iterm2-...@googlegroups.com
When using Karabiner the first thing to check is what keystroke iTerm2 is receiving. The easiest way to do this is to make a debug log and look for the event that the OS sent. Select the menu item iTerm2 > Toggle debug logging, press the key, and then select the menu item again to write it out to /tmp/debuglog.txt. Then search for "Received KeyDown event". You'll see something like:

1573336424.995116 iTermApplication.m:406 (-[iTermApplication handleKeyDownEvent:]): Received KeyDown event: NSEvent: type=KeyDown loc=(-283.074,1341.68) time=13140.8 flags=0x42100 win=0x101d22070 winNum=182 ctxt=0x0 chars="^V" unmodchars="v" repeat=0 keyCode=9. Key window is <iTermWindow: 0x101d22070 frame=NSRect: {{375, 82}, {1956, 1325}} title=y alpha=1.000000 isMain=1 isKey=1 isVisible=1 delegate=0x104129e40>. First responder is <PTYTextView: 0x10416a960 frame=NSRect: {{0, 2}, {1956, 1277}} visibleRect=NSRect: {{0, 0}, {1956, 1277}} dataSource=<VT100Screen: 0x104160e00 grid:<VT100Grid: 0x600002c38300 size=278 x 75, cursor @ (41,55)>> delegate=<PTYSession: 0x104944a00 278x75 metal=1 id=2AD61ABB-445E-484E-BED1-51BAAFEC4AA7> window=<iTermWindow: 0x101d22070 frame=NSRect: {{375, 82}, {1956, 1325}} title=y alpha=1.000000 isMain=1 isKey=1 isVisible=1 delegate=0x104129e40>>

The "flags" (0x42100 in this example) gives the modifier keys. It is a bitmask composed of the following values:

    NSEventModifierFlagShift              = 1 << 17, // Set if Shift key is pressed.

    NSEventModifierFlagControl            = 1 << 18, // Set if Control key is pressed.

    NSEventModifierFlagOption             = 1 << 19, // Set if Option or Alternate key is pressed.

    NSEventModifierFlagCommand            = 1 << 20, // Set if Command key is pressed.


Also of interest is the "unmodchars", which gives the character that was pressed, ignoring the option and control key.

In your case, if things are working as you describe, you'd see a mask that includes 0x160000 (there may be other bits set as well, which can be disregarded) and unmodchars of "v".


--
You received this message because you are subscribed to the Google Groups "iterm2-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to iterm2-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/iterm2-discuss/44932bdb-ad50-470b-a6a1-68b9a121fbec%40googlegroups.com.

Chaitanya Kuchimanchi

unread,
Nov 10, 2019, 6:24:30 PM11/10/19
to iterm2-discuss
Thanks for the reply, George. I've read the debug log and here's what I found:

First of all, I tried this. 

sed -n l 
press Ctrl-F ( Received KeyDown event: NSEvent: type=KeyDown loc=(958.191,631.645) time=326173.5 flags=0x40101 win=0x7f83f3d18f80 winNum=21165 ctxt=0x0 chars=" " unmodchars="f" )
press Cmd+Shift+Control+F (Received KeyDown event: NSEvent: type=KeyDown loc=(958.191,631.645) time=326179.5 flags=0x16010b win=0x7f83f3d18f80 winNum=21165 ctxt=0x0 chars=" " unmodchars="F")

it does have 0x16 as you expected, but not sure why neither sed nor vim -- were picking up and getting any keystrokes recognised?  Appreciate you help and attaching the debug log here

Many thanks in advance

To unsubscribe from this group and stop receiving emails from it, send an email to iterm2-...@googlegroups.com.
debuglog.txt

George Nachman

unread,
Nov 11, 2019, 2:24:30 AM11/11/19
to iterm2-...@googlegroups.com
I went back and re-read your original message, and this is the key part:

> However, while working in terminal (using iterm2 of course and it's fantastic :) ), if I then press, say,  Caps-lock+V (which is nothing but Cmd+Shift+control+V because of the karabiner mapping) i don't see anything happening - I mean no sequence is being sent to the program (either bash/zsh/vim that's running in the terminal) 

If I understand correctly, you intend capslock+V to act as cmd-shift-control-V.

All keystrokes that include Cmd are swallowed by iTerm2 and not passed on to the app running within it.


To unsubscribe from this group and stop receiving emails from it, send an email to iterm2-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/iterm2-discuss/a953764e-8b52-41c5-9152-42ae9678ed3f%40googlegroups.com.

Chaitanya Kuchimanchi

unread,
Nov 11, 2019, 3:02:28 PM11/11/19
to iterm2-discuss
Ah :( It makes sense now then.

Can I ask you for a suggestion then? I'm looking for a fairly unique prefix (as I said earlier, sort of a hyper key) to prefix my custom commands. 

Considering 'Cmd' is swallowed by iterm, the other options I've are Shift+Control+Option. However, looks like Option as it is, isn't much useful unless I set it to 'Esc+' in which case, Shift+Control+Option+key effectively becomes Esc+Ctrl+key(in uppercase). 

Which means, my hyper key is the sequence of 'Esc+Control' which I think is very weak

In karabiner (NOT that I'm asking for these features, but trying to understand what options I have with iterm2) - you get unlimited possibilities because I think it allows you to differentiate between left and right modifiers, there by making a configuration like below possible:

Hyper key = right_control+right_shift+right_option
Hyper Key + h = move left by a character (i.e., mapped to left-arrow)
Hyper Key + left_Option + h = move left by a word (i.e., mapped to option+left arrow)
Hyper Key + left_Option + left_Shift + h = move left by a word AND also select it (i.e., mapped to option + shift + left arrow)

Can you please suggest how much close I can get with simulating such configuration here? (if at all possible?) 

Just to let you know why I'm after this: I plan to use common text navigation/selection shortcuts across all apps to make my life easy. The above karabiner mappings are for Mac OS, so my intention is to simulate similar mappings for say bash and vim - that I run inside the terminal - (In all these, LHS , i.e., the keys that I press remain the same, but RHS varies as per the target application) 

Thanks again for all the help and the wonderful iterm2 :) 

George Nachman

unread,
Nov 14, 2019, 12:46:53 AM11/14/19
to iterm2-...@googlegroups.com
It's going to be hard to achieve your goals. You have to fight app by app. For one thing, multiple modifiers are usually not reported in terminal emulators. The main exception is that option when sending esc will preserve the shift key's state.

If you use mostly apps that support CSI u, that gives you a lot more options. But AFAIK neovim is the only popular app that does.

I guess esc+shift+something is going to be your best bet. You can remap any keystroke to send such a sequence in Prefs>Keys:

image.png
The physical keystroke can be whatever you want with the remapping strategy. The hard part is to get every program in the terminal to interpret esc+whatever the same way. You'll need to modify inputrc, your editor's config, and so on.

To unsubscribe from this group and stop receiving emails from it, send an email to iterm2-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/iterm2-discuss/456f55b6-cfaf-4138-9235-5e9722a66718%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages