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

Azerty not working #32

Open
Armaklan opened this issue May 19, 2015 · 20 comments
Open

Azerty not working #32

Armaklan opened this issue May 19, 2015 · 20 comments

Comments

@Armaklan
Copy link

Azerty keyboard dont work.

Letter press is correctly print in screen, but all symbol (number, ponctuation, ...) is not from azerty keyboard.

@coolwanglu
Copy link
Owner

That's probably because the scancode is used.
I wonder if you have tried Atom (the editor), is your keyboard working well there?

@Armaklan
Copy link
Author

Keyboard work in Atom Editor.

@coolwanglu
Copy link
Owner

OK, let me see if I can find the issue, as the code that processes keyboard events were taking from Atom.
But it could be difficult as I don't have an Azerty keyboard.

@Armaklan
Copy link
Author

Ok. Feel free to ask me to test some modification.

@Armaklan
Copy link
Author

I try to replace keydown event by keypress event.
Many character work well (like : ) by i think we must rebind code of function button => actually "z" is bind on F11

@q12321q
Copy link

q12321q commented Jul 26, 2015

Indeed the keypress event is the only way to go. AFAIK it's not possible to properly handle localized or punctuation characters via the keydown event. Unfortunately, some special keys like or do not fire the keypress event. So we need to keep both.

I propose to keep keydown for the special keys and then handle others with the keypress event.
I'll fork and try to implement something as a POC. It'll need a lot of tests to handle every cases.

@coolwanglu: you don't need a physical AZERTY keyboard to test. It's depend on which system you are but you can easily change the layout.

@coolwanglu
Copy link
Owner

@q12321q Is there a library for this?

@q12321q
Copy link

q12321q commented Jul 26, 2015

for what?

@coolwanglu
Copy link
Owner

Translate keycode to localized characters.

@q12321q
Copy link

q12321q commented Jul 26, 2015

Unfortunately, no. There're many attempts but all of them seems clumsy/kludgy and not exhaustive.
If you look on the web about keypress vs keydown, you'll find a lot of guys trying to solve this issue. The only reasonable solution is for me to use the keypress event.

@q12321q
Copy link

q12321q commented Jul 26, 2015

And here we are lucky because keycode are also local to every browser. For a same character, you can have different keycode in chrome and firefox...

https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/keyCode

@q12321q
Copy link

q12321q commented Jul 26, 2015

I updated the fork (https://github.com/q12321q/neovim-e) with the implementation of my previous comment:

  • add keypress event to handle "printable characters"
  • keep keydown event for specials characters only
    From my first tests, It works pretty well except for Ctrl-NonASCIICharacters: it's major issue since Ctrl-] is a common shortcut. We'll have to think of something.

@coolwanglu what do you think?

@q12321q
Copy link

q12321q commented Jul 26, 2015

Some readings:
atom/atom-keymap#37
https://github.com/andischerer/atom-keyboard-localization

It won't be that easy to solve...

@coolwanglu
Copy link
Owner

@q12321q Indeed I switched 'keypress' to 'keydown' before, just to handle special characters. To use both events, we need to make sure that each physical key press is handled only once by either handler, and we might need to test on different platforms.

atom-keyboard-localiztion looks neat, do you think we can use its code?

@q12321q
Copy link

q12321q commented Jul 27, 2015

I start to think that the keypress solution is maybe a dead end...
I'm not sure we will be able to handle the Ctrl chords like that.
Keypress give us the charCode of the result of Ctrl-a but not the charCode of "a" + the fact that with use Ctrl. So I can't build the string "< C-a >" to send to nvim but instead I directly send the character itself. I'm fortunate that it works with a but it doesn't for all non ASCII and punctuation characters.
I'll look a bit more into atom-keyboard-localization

@coolwanglu
Copy link
Owner

Indeed. That's quite a mess.
Hopefully with the localization module, a mapping can be chosen based on the keyboard layout specified by users, and the key events will be simply mapped accordingly.
Good luck!

@q12321q
Copy link

q12321q commented Jul 29, 2015

OK, I did some search again and I found no perfect solution. Atom has the same issues and like us have no clean solution. atom-keyboard-localization fix a lot of things but has the major drawback to maintain a non exhaustive tables of key mappings and the need to manually define on which keyboard you are.

But we have a hope: DOM3 with the implementation of the key value in the keydown event:
https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key
It'll solve all our problems and will drastically lighten the code.
The problem is it's not yet implemented in chrome:
https://www.chromestatus.com/feature/4748790720364544
They're working on it and we may hope to have it soon.
Firefox has already done the job and you can try it on the lastest version with this page:
https://dvcs.w3.org/hg/d4e/raw-file/tip/key-event-test.html

In the mean time if you want, we can implement something like atom do:

  • keypress handle all singles characters without Ctrl or Alt
    • So all international and punctuation characters are handle
    • Dead keys are handle ( ^ + e -> ê)
    • Alt+Number works ( Alt+0199 -> Ç)
  • keydown handle special keys and key combination
    • Use localized keycode tables like atom-keyboard-localization to handle Ctrl+, Alt+ and Meta+
    • had a option somewhere to select localized layout

You'll always have the correct character when typing a text and we could only have limitations on key combinations.

Thoughs?

@coolwanglu
Copy link
Owner

I don't know how long we should wait for KeyboardEvent. I remember our keydown and keypress events can also be simplified with it.

So it depends on whether you want this feature in the near future.

@q12321q
Copy link

q12321q commented Jul 30, 2015

Of course it could take at least several months or years to wait for the KeyboardEvent.key feature. Dev is always longer than we think but it's good to know that we'll have a real solution.
It's pretty important for a text editor to be reliable while typing characters :)

Today, neovim-e is unusable on non-US keyboard: the ':' is not available.
It also depends how much you want to invest into neovim-e: is it a POC or a real software with a futur?

@coolwanglu
Copy link
Owner

@q12321q It started as a simply POC, or a toy :). But I'm happy to find that people started to report bugs and send PRs. While I will have limited time on this project, I'd love to make fixes and merge PRs.

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

3 participants