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

Added ctrl_key_to_key() function #17263

Closed
Closed
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

@@ -463,7 +463,13 @@ impl Window {
fn handle_window_event(&self, event: glutin::Event) -> bool {
match event {
Event::ReceivedCharacter(ch) => {
self.handle_received_character(ch)
//For CTRL + Key event, we receive the escaped unicode of the combination.
//However:
// 1. It's useless: we already store the information about the CTRL keypress with toggle_keyboard_modifiers()
// 2. In order to match CTRL+key shortcuts, we need `ch` to hold the actual character, not the ctrl+key combination
//As a result, we need to convert ctrl+key escaped unicodes to the actual character being pressed

This comment has been minimized.

@paulrouget

paulrouget Jun 12, 2017

Contributor

Fix the comment formatting, and move it in the ctrl_key_to_key function.

let clean_ch = ctrl_key_to_key(ch);
self.handle_received_character(clean_ch);
}
Event::KeyboardInput(element_state, _scan_code, Some(virtual_key_code)) => {
self.handle_keyboard_input(element_state, _scan_code, virtual_key_code);
@@ -1397,6 +1403,44 @@ fn filter_nonprintable(ch: char, key_code: VirtualKeyCode) -> Option<char> {
}
}

fn ctrl_key_to_key(ch: char) -> char {
match ch {
'\u{0}' => '@',
'\u{1}' => 'a',
'\u{2}' => 'b',
'\u{3}' => 'c',
'\u{4}' => 'd',
'\u{5}' => 'e',
'\u{6}' => 'f',
'\u{7}' => 'g',
'\u{8}' => 'h',
'\t' => 'i',
'\n' => 'j',
'\u{b}' => 'k',
'\u{c}' => 'l',
'\r' => 'm',
'\u{e}' => 'n',
'\u{f}' => 'o',
'\u{10}' => 'p',
'\u{11}' => 'q',
'\u{12}' => 'r',
'\u{13}' => 's',
'\u{14}' => 't',
'\u{15}' => 'u',
'\u{16}' => 'v',
'\u{17}' => 'w',
'\u{18}' => 'x',
'\u{19}' => 'y',
'\u{1a}' => 'z',
'\u{1b}' => '[',
'\u{1c}' => '\\', //Need to escape \
'\u{1d}' => ']',
'\u{1e}' => '^',
'\u{1f}' => '_',
_ => ch
}
}

This comment has been minimized.

@paulrouget

paulrouget Jun 12, 2017

Contributor

Do you need more? Like for "Ctrl +" , "Ctrl digit", "Ctrl ," … ? Do we even need to cover everything?

This comment has been minimized.

@jklepatch

jklepatch Jun 12, 2017

Author Contributor

Seems like only certain combinations of CTRL + Key map to a specific ASCII code. For other combinations, it simply maps to the Key ASCII code.
See those links:
https://en.wikipedia.org/wiki/Control_character
"..this produces one of the 32 ASCII control codes between 0 and 31."
http://academic.evergreen.edu/projects/biophysics/technotes/program/ascii_ctrl.htm
http://www.physics.udel.edu/~watson/scen103/ascii.html

This comment has been minimized.

@paulrouget

paulrouget Jun 13, 2017

Contributor

Ok!


// These functions aren't actually called. They are here as a link
// hack because Skia references them.

ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.