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

emit physical key presses when a non-Latin layout is active #4461

Merged
merged 2 commits into from
May 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions crates/egui-winit/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -746,15 +746,19 @@ impl State {
physical_key
);

if let Some(logical_key) = logical_key {
// "Logical OR physical key" is a fallback mechanism for keyboard layouts without Latin characters: it lets them
// emit events as if the corresponding keys from the Latin layout were pressed. In this case, clipboard shortcuts
// are mapped to the physical keys that normally contain C, X, V, etc.
// See also: https://github.com/emilk/egui/issues/3653
TicClick marked this conversation as resolved.
Show resolved Hide resolved
if let Some(active_key) = logical_key.or(physical_key) {
if pressed {
if is_cut_command(self.egui_input.modifiers, logical_key) {
if is_cut_command(self.egui_input.modifiers, active_key) {
self.egui_input.events.push(egui::Event::Cut);
return;
} else if is_copy_command(self.egui_input.modifiers, logical_key) {
} else if is_copy_command(self.egui_input.modifiers, active_key) {
self.egui_input.events.push(egui::Event::Copy);
return;
} else if is_paste_command(self.egui_input.modifiers, logical_key) {
} else if is_paste_command(self.egui_input.modifiers, active_key) {
if let Some(contents) = self.clipboard.get() {
let contents = contents.replace("\r\n", "\n");
if !contents.is_empty() {
Expand All @@ -766,7 +770,7 @@ impl State {
}

self.egui_input.events.push(egui::Event::Key {
key: logical_key,
key: active_key,
TicClick marked this conversation as resolved.
Show resolved Hide resolved
physical_key,
pressed,
repeat: false, // egui will fill this in for us!
Expand Down
8 changes: 5 additions & 3 deletions crates/egui/src/data/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -361,10 +361,12 @@ pub enum Event {

/// A key was pressed or released.
Key {
/// The logical key, heeding the users keymap.
/// Most of the time, it's the logical key, heeding the active keymap -- for instance, if the user has Dvorak
/// keyboard layout, it will be taken into account.
///
/// For instance, if the user is using Dvorak keyboard layout,
/// this will take that into account.
/// If it's impossible to determine the logical key on desktop platforms (say, in case of non-Latin letters),
/// `key` falls back to the value of the corresponding physical key. This is necessary for proper work of
/// standard shortcuts that only respond to Latin-based bindings (such as `Ctrl` + `V`).
key: Key,

/// The physical key, corresponding to the actual position on the keyboard.
Expand Down
Loading