Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backslash key on Japanese Macs #848

Closed
benallan opened this issue Sep 1, 2018 · 6 comments
Closed

Backslash key on Japanese Macs #848

benallan opened this issue Sep 1, 2018 · 6 comments

Comments

@benallan
Copy link

benallan commented Sep 1, 2018

The backslash key on Japanese computers is usually set to produce a currency yen mark "¥" by default. We can remap this in the system settings to produce the backslash and not the yen mark:
d918ab13-e575-44ef-880a-b177b145d6f0

This works for me system wide, but it does not work in kitty for some reason. Even with a blank config, kitty seems to produce ¥ instead of \.

I wonder if there's any way for kitty to respect the system wide option? I realise that you probably don't have access to a Japanese mac so it might not be worth the trouble.

Instead, can we use map ... send_text to work around this? I've tried a few times but can't seem to find the right keycode to input.

Here's what I've tried in kitty.conf:

map ¥ send_text all \u005C
map 0x5d send_text all \u005C
map 93 send_text all \u005C

Here's the output of xev when pressing the ¥ key:

KeyPress event, serial 34, synthetic NO, window 0x600001,
    root 0x1d1, subw 0x0, time 2471733143, (98,-13), root:(507,59),
    state 0x0, keycode 101 (keysym 0xa5, yen), same_screen YES,
    XLookupString gives 2 bytes: (c2 a5) "¥"
    XmbLookupString gives 2 bytes: (c2 a5) "¥"
    XFilterEvent returns: False

Here's the output of Key Codes when pressing the ¥ key:
bcf62c38-7293-4486-a96d-075ad88dd400

How should I write that map command in kitty.conf?

@kovidgoyal
Copy link
Owner

You can see what key events kitty receives by running it as

kitty --debug-keyboard

@benallan benallan changed the title Backlash key on Japanese Macs Backslash key on Japanese Macs Sep 1, 2018
@benallan
Copy link
Author

benallan commented Sep 1, 2018

Thanks, that's really helpful.

Here's the output:

2018-09-01 14:35:51.600 kitty[30020:36431022] char_count: 1 cocoa text: 5c
2018-09-01 14:35:51.600 kitty[30020:36431022] scancode: 0x5d (¥) mods: none text: c2 a5 glfw_key: UNKNOWN

So if it's not recognized by glfw, am I out of luck?

@kovidgoyal
Copy link
Owner

kitty has a mechanism to bind native keycodes as well, but it is only implemented for XKB (X11/Wayland). You could in theory implement it for cocoa as well, but that is a fair amount of work. See https://sw.kovidgoyal.net/kitty/conf.html#keyboard-shortcuts which talks about using XKB key names. You'd basically need to implement the key_for_native_key_name() function for cocoa in keys.c line number 226

Or you can try to investigate why glfw does not respect the system wide setting, relevant code is the keyDown function in glfw/coca_window.m

@benallan
Copy link
Author

benallan commented Sep 4, 2018

Fast work, thanks a lot! I just had a quick test with the latest code, but still can't seem to get it to work. Mapping the yen/backlash key didn't seem to work, and I also tried mapping the x key as a more straightforward test.

Is there something else needed to get this working on macos?

kitty.conf:

map 0x7 send_text all test
map shift+0x7 send_text all test

Output of x keypress with --debug-keyboard on:

2018-09-04 17:59:48.360 Python[48533:40890897] char_count: 1 cocoa text: 78
2018-09-04 17:59:48.360 Python[48533:40890897] scancode: 0x7 (x) mods: none text: 78 glfw_key: X
on_key_input: glfw key: 88 native_code: 0x7 action: PRESS mods: 0x0 text: 'x' state: 0 sent text to child
on_key_input: glfw key: 88 native_code: 0x7 action: RELEASE mods: 0x0 text: '' state: 0 ignoring as keyboard mode does not allow release events

@kovidgoyal
Copy link
Owner

oops, should be fine now.

@benallan
Copy link
Author

benallan commented Sep 4, 2018

Working fine now, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants