[posila] Ctrl+Anykey doesn't work when the game is started with Russian keyboard layout

This subforum contains all the issues which we already resolved.
Post Reply
linux_zealot
Burner Inserter
Burner Inserter
Posts: 13
Joined: Thu Feb 28, 2019 10:26 am
Contact:

[posila] Ctrl+Anykey doesn't work when the game is started with Russian keyboard layout

Post by linux_zealot »

Problematic behavior

While playing Factorio I use Ctrl+C, Ctrl+V quite often. Most of the time I start the game they work, but for some runs they don't. The only solution to the problem I know is to restart the game, but after restarting it again can work and can not work. On bad days when Ctrl+C, Ctrl+V refused to work I had to use mouse to copy/paste.

When Ctrl+C, Ctrl+V don't work they behave as if Ctrl is not pressed. For example Ctrl+X swaps panels 1<->2 at the bottom of the screen as if X is pressed.

A little bit of background

I, as most other Russian speakers, use two keyboard layouts. US for entering Latin characters and RU for entering Cyrillic. There is a key combination (Alt+Shift most often) to switch between these two layouts. People switches between these two layouts quite often. For example to type an URL in browser you had to use US layout and instant messaging is most often done in RU layout.

It is important to note that the currently active layout at the start of the game is basically random thing that depends on what the user typed last.

Also note that I use Linux, perhaps this problem is Linux specific. I haven't tested other operating systems.

What I discovered

At some point I decided to investigate what exactly is going on. I would like to note that I have read viewtopic.php?f=7&t=65881 and https://www.factorio.com/blog/post/fff-259 and what I concluded is that the behavior I observe is not intended and erroneous as I found out only Ctrl key is broken.

I discovered that
  • The problem manifests only when the game is started with Russian keyboard layout. When the game is started with US Ctrl+Anykey works as expected.
  • Switching keyboard layout in game doesn't help, only what matters is the keyboard layout at game start (which is, as I noted above is basically random for Russian speakers)
  • Only Ctrl+Somekey shortcuts are broken. Normal keys works well as well as Alt+Anything.
Possible cause

I noticed that when the game is started with Russian layout, in Settings+Control it prints Cyrillic letters that maps to the same key on the keyboard. For example instead of W it prints Ц, R->К, Shift+R->Shift+К. It is suspicious that for all Ctrl+X, Ctrl+C, Ctrl+V it prints Ctrl+KEY_0 (number zero). I tested all keys on my keyboard and I haven't found the key that matches KEY_0. If I assign Ctrl+Z, Ctrl+X, Ctrl+C, Ctrl+V manually to Ctrl+Я, Ctrl+Ч, Ctrl+С, Ctrl+М, they will work. So game is perfectly capable to handle Ctrl+Somekey and the problem is with configuration.

I attached three screenshots.
original.png
original.png (1.8 MiB) Viewed 2557 times
is how Settings->Control looks when key bindings are reset to the default value and the game is started when Russian keyboard layout was active (you can see Ctrl+KEY_0 is set for all Ctrl+Somekey shortcuts).
russian.png
russian.png (1.8 MiB) Viewed 2557 times
is when I assigned correct keys for Russian keyboard layout.
english.png
english.png (1.8 MiB) Viewed 2557 times
is when I saved settings and restarted the game with english keyboard layout as you can see main and alternative keys match.

This is how config file ~/.factorio/config/config.ini looks like when saved from Russian keyboard layout:

Code: Select all

; copy=CONTROL + keycode-0
copy-alternative=CONTROL + C
; cut=CONTROL + keycode-0
cut-alternative=CONTROL + X
; paste=CONTROL + keycode-0
paste-alternative=CONTROL + V
; undo=CONTROL + keycode-0
undo-alternative=CONTROL + Z
This is how it looked when saved from English keyboard layout:

Code: Select all

; copy=CONTROL + C
copy-alternative=CONTROL + C
; cut=CONTROL + X
cut-alternative=CONTROL + X
; paste=CONTROL + V
paste-alternative=CONTROL + V
; undo=CONTROL + Z
undo-alternative=CONTROL + Z
Let me know it I can provide any additional information.

Final remark

Although my original bug report was about not working Ctrl+Somekey key combinations. I would like to suggest one minor tweak to Settings->Control menu.

At the moment it prints either english or russian letters depending on what keyboard layout was when the game started. Can this dialog redraws and updates letters when user change keyboard layout while in-game?

posila
Factorio Staff
Factorio Staff
Posts: 5147
Joined: Thu Jun 11, 2015 1:35 pm
Contact:

Re: [posila] Ctrl+Anykey doesn't work when the game is started with Russian keyboard layout

Post by posila »

Thanks for the report.
Default keybinding being Control + KEY_0 is fixed for 0.17.24
linux_zealot wrote:
Sun Mar 31, 2019 11:56 am
Final remark

Although my original bug report was about not working Ctrl+Somekey key combinations. I would like to suggest one minor tweak to Settings->Control menu.

At the moment it prints either english or russian letters depending on what keyboard layout was when the game started. Can this dialog redraws and updates letters when user change keyboard layout while in-game?
That's how it works on Windows (and I belive on macOS too). It seems that SDL doesn't receive keyboard layout change event; this might be specific to your Linux environment (window manager, some configuration or something like that) ... (I vaguely remember this being an issue when using Allegro too, so it might be just not easy to do on Linux in a way that would always work: 41114)

linux_zealot
Burner Inserter
Burner Inserter
Posts: 13
Joined: Thu Feb 28, 2019 10:26 am
Contact:

Re: [posila] Ctrl+Anykey doesn't work when the game is started with Russian keyboard layout

Post by linux_zealot »

Thank you for a quick fix.
That's how it works on Windows (and I belive on macOS too). It seems that SDL doesn't receive keyboard layout change event; this might be specific to your Linux environment (window manager, some configuration or something like that)
Ok, I think I can make a simple SDL2 program to check if this is the case. My environment is indeed quite arcane.

I'll create a new bug report if the game receives SDL_KEYMAPCHANGED.

ametalon
Manual Inserter
Manual Inserter
Posts: 4
Joined: Thu Apr 04, 2019 7:30 pm
Contact:

Re: [posila] Ctrl+Anykey doesn't work when the game is started with Russian keyboard layout

Post by ametalon »

I have related inconvenience with Dvorak layout (https://www.kaufmann.no/roland/dvorak/). I'm not sure if following is a bug, but it was unexpected for me.

If I start the game in QWERTY layout:
Move down - S
Copy - Ctrl+C
Deconstruct - Alt+D

and if I switch to Dvorak while staying on "Settings - Controls" screen, bindings change to:
Move down - O
Copy - Ctrl+J
Deconstruct - Alt+E

All of this is expected and very useful, thanks.

Now reverse situation, if I start the game in Dvorak layout:
Move down - O
Copy - Ctrl+C (physical location of button "I" on QWERTY layout)
Deconstruct - Alt+E

and if I switch to QWERTY while staying on "Settings - Controls" screen, bindings change to:
Move down - S
Copy - Ctrl+I
Deconstruct - Alt+D


What is unexpected for me is that "Ctrl+<key>" shortcuts behave not like "Alt+<key>" and "Shift+<key>" shortcuts.
In Ctrl+<key> shortcuts <key> does not depend on startup layout, so C-QWERTY stays C-Dvorak, which are different physical buttons, while in Alt+<key> shortcuts <key> changes, so D-QWERTY becomes E-Dvorak, which is the same physical button.
I find it very useful that physical buttons I press in the game stay the same regardless of startup or current layout, sadly Ctrl+<key> do require to use different physical buttons.

To be clear, I like how all keybindings except Ctrl+<Z,X,C,V> make it look like I'm always on QWERTY regardless of startup or current layout.
To alleviate this minor inconvenience I added alternative bindings for all Ctrl+<key> shortcuts (or I can just always start the game in QWERTY, that works for me too), so all this stuff is not a problem for me whatsoever, just wanted to clarify the situation.

Quote from relevant part of https://www.factorio.com/blog/post/fff-259
To fix these kind of shortcuts we determine the appropriate default scan-codes at start-up, so that undo is always Ctrl+Z, regardless of your layout, but the action will stay bound to those keys if you change keyboard layout at runtime
So, there is either inconsistency or some logic I don't understand.

I'm using Windows 10, Steam versions 0.17.23-25 behave identically.

posila
Factorio Staff
Factorio Staff
Posts: 5147
Joined: Thu Jun 11, 2015 1:35 pm
Contact:

Re: [posila] Ctrl+Anykey doesn't work when the game is started with Russian keyboard layout

Post by posila »

ametalon wrote:
Thu Apr 04, 2019 9:28 pm
Quote from relevant part of https://www.factorio.com/blog/post/fff-259
To fix these kind of shortcuts we determine the appropriate default scan-codes at start-up, so that undo is always Ctrl+Z, regardless of your layout, but the action will stay bound to those keys if you change keyboard layout at runtime
So, there is either inconsistency or some logic I don't understand.
Hey, this is unrelated to the bug report.

So, our assumption is that the most people use one keyboard layout and don't switch layouts at runtime; Another assumption is that everybody is used to Ctrl+Z be Undo, regardless of which physical key produces character Z. Because now the game cares about physical locations of key (indetified by scan code) instead of what the keys actually mean on current layout, it determines which physical key is 'Z' during startup and uses that as default keybinding for Undo operation, but from that point forward, the game doesn't care about your layout anymore and works with scancodes only (physical locations of keys). So, unless you rebind the shortcuts (even to the same thing it defaulted to) the game will figure out what physical keys should trigger Undo on startup, but then sticks to those physical keys during runtime. If you do rebind them, the game will use the physical keys you rebound it to.

"will stay bound to those keys" means "those physical keys", so your observation is in line with the sentence you quoted. The game started with Copy being Ctrl+C regardless of what your layout was, but when you changed the layout, Copy stayed bound to the physical keys that corresponded to Ctrl+C when the game started.
ametalon wrote:
Thu Apr 04, 2019 9:28 pm
To alleviate this minor inconvenience I added alternative bindings for all Ctrl+<key> shortcuts (or I can just always start the game in QWERTY, that works for me too), so all this stuff is not a problem for me whatsoever, just wanted to clarify the situation.
Changing settings is expected course of action if default behavior doesn't suit you, that's what the settings are there for :)

ametalon
Manual Inserter
Manual Inserter
Posts: 4
Joined: Thu Apr 04, 2019 7:30 pm
Contact:

Re: [posila] Ctrl+Anykey doesn't work when the game is started with Russian keyboard layout

Post by ametalon »

Oh, I understand that paragraph from FFF-259 now, thanks for detailed explanation.
You introduced notion of "universal shortcuts" (Ctrl+<key>) which bound to the keys familiar to a user from other programs. And other shortcuts (Alt+<key>) are "internal" or in other words game specific and therefore bound to physical buttons from QWERTY layout.
That's actually makes a lot of sense, thank you for such care for details.
Sorry for posting in unrelated bug report, I misunderstood "universal shortcuts" logic and thought it is related.

Post Reply

Return to “Resolved Problems and Bugs”