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

alt-gr meta key not available? #1066

Closed
snowiow opened this issue Dec 7, 2015 · 7 comments
Closed

alt-gr meta key not available? #1066

snowiow opened this issue Dec 7, 2015 · 7 comments
Assignees
Labels
feature-request Request for new features or functionality verified Verification succeeded VIM VIM issue
Milestone

Comments

@snowiow
Copy link

snowiow commented Dec 7, 2015

From what I've seen in the docs it looks like that the alt-gr meta key can't be mapped for keybindings in the package.json for a plugin. Will this be supported in the future or is there any other way? Thanks in advance.

@egamma egamma added the *question Issue represents a question, should be posted to StackOverflow (VS Code) label Dec 7, 2015
@guillermooo
Copy link

#713

@alexdima
Copy link
Member

alexdima commented Dec 7, 2015

pressing AltGr+X in all OSes results in Ctrl+Alt+X where X is a key code. So to map AltGr+P for example you would map Ctrl+Alt+P

@alexdima alexdima closed this as completed Dec 7, 2015
@snowiow
Copy link
Author

snowiow commented Dec 7, 2015

Doesn't work for me. I tried to map the open curly to alt-gr-7. Following your tip, I mapped it to Ctrl+Alt+7, which is working, if I press that combination. But if I press alt-gr+7, it still writes 7

@alexdima
Copy link
Member

alexdima commented Dec 7, 2015

@snowiow I'm not sure I understand the problem? Can you please share the keybinding rule or your use-case?

@alexdima alexdima reopened this Dec 7, 2015
@snowiow
Copy link
Author

snowiow commented Dec 8, 2015

Sure I Have got something like this in the plugin's package.json

"keybindings": {
    { "key": "Ctrl+Alt+7", "command": "extension.v_{", "when": "editorTextFocus" }
}

Then in the extension.ts I register this command to a handler method

export function activate(context: vscode.ExtensionContext) {
    ....
    registerCommand(context, 'extension.v_7', () => handle("7"));
    registerCommand(context, 'extension.v_{', () => handle("{"));
    ....
}

function handle(key:string) {
    console.log(key); //Prints "{" on Ctrl+Alt+7 and "7" on alt-gr+7
}

@egamma egamma mentioned this issue Dec 8, 2015
34 tasks
@alexdima
Copy link
Member

alexdima commented Dec 8, 2015

@snowiow Thank you for clarifying. I know this is currently the only way to do anything with keys from an extension, but the keybindings rules are a pretty bad way to do character input. The reason is that the keybinding rules are interpreted on browser event keydown where we're only receiving key codes and not characters. (See #713 for an explanation of how you cannot really support different keyboard layouts going with the keybindings approach).

Also, you might have noticed that we do not bind by default any keybindings that produce characters. (e.g. no key binding for pressing a, shift+a, b, etc.). That is because the keyboard dispatcher interpretes the pressed keys and if a key has no rule, then we do not call preventDefault() on the keydown event. Then, browsers will do their thing, and they will follow up with keypress and input events. We don't even use that to figure out the character input, since the properties in a keypress are inconsistent across browsers and they wouldn't help in the CJK case. Instead, we install a timeout and then we look inside our textarea input and check it's .value to figure out what was typed. We then take that value and call an internal type handler.

I have digged into Chromium sources last week and not even Chromium knows reliably what character would be produced on a keydown on all the platforms it supports. Chromium itself also reacts to the OS events and I think some OSes do not always give the produced characters. Also, there is the composition case for e.g. CJK characters.

I have an item on the plan (#917) to understand how VIM extensions could be implemented better:

I think at least in part, supporting VIM extensions consists of providing a means to redirect the character input and instead of calling the internal type handler, to be able to call a command on an extension or perhaps toggle between the two.

@egamma egamma modified the milestone: Backlog Dec 10, 2015
@egamma egamma mentioned this issue Jan 6, 2016
59 tasks
@jpoon jpoon mentioned this issue Jan 7, 2016
@egamma egamma added feature-request Request for new features or functionality VIM VIM issue and removed *question Issue represents a question, should be posted to StackOverflow (VS Code) labels Jan 8, 2016
@alexdima alexdima modified the milestones: March 2016, Backlog Mar 12, 2016
@alexdima
Copy link
Member

@snowiow @guillermooo Thank you for your patience with this.

Please see https://github.com/alexandrudima/vscode-vim if you are authoring a vim emulation extension for VS Code - it is a sample that shows how to capture typed characters (not through keybinding rules).

@alexdima alexdima added the verified Verification succeeded label Mar 21, 2016
@vscodebot vscodebot bot locked and limited conversation to collaborators Nov 18, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature-request Request for new features or functionality verified Verification succeeded VIM VIM issue
Projects
None yet
Development

No branches or pull requests

4 participants