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

Add ScanCode enum. #862

Open
linkpy opened this issue Nov 13, 2020 · 12 comments
Open

Add ScanCode enum. #862

linkpy opened this issue Nov 13, 2020 · 12 comments
Labels
A-Input Player input via keyboard, mouse, gamepad, and more C-Feature A new feature, making something new possible

Comments

@linkpy
Copy link

linkpy commented Nov 13, 2020

What problem does this solve or what need does it fill?

For better keyboard layout support. KeyCode depends on the user's keyboard layout while scancodes doesn't (KeyCode::A wouldn't be the same physical key on a QWERTY or an AZERTY keyboard, while ScanCode::A would be the A key on a QWERTY, while it would be the Q key on an AZERTY). Scancodes are already supported in events, but not with Input<T>.

Describe the solution would you like?

Add a ScanCode enum. A good list to begin with would be SDL's ScanCode. If i remember correctly, SDL_Scancode enumeration is based on the USB standard specification.

Describe the alternative(s) you've considered?

An alternative would be to implement that in every project, but I think that kind of things would be better if directly inside of the engine.

Additional context

None

@karroffel karroffel added C-Feature A new feature, making something new possible A-Input Player input via keyboard, mouse, gamepad, and more labels Nov 13, 2020
@chayleaf
Copy link

chayleaf commented Dec 11, 2020

Scan codes are important, but text input is more than just key codes, IME support needs to be added as well. AFAIK currently no windowing solution (winit, SDL, GLFW) handles IMEs perfectly.

In order for IMEs to work in fullscreen application (and work well in non-fullscreen applications), the app has to render the IME window itself by querying the system for current IME state. IMEs also work differently for Chinese, Japanese and Korean. On Windows it can be done with something like https://github.com/microsoft/Windows-classic-samples/tree/master/Samples/IME

There's more important info here https://www.gamasutra.com/blogs/StoyanNikolov/20130927/201151/Game_i18n_via_IME.php

On Android the common approach is to send the user into a fullscreen native textbox upon tapping the in-game textbox. On the web there's no IME API currently available or planned, but the browser isn't fullscreen - perhaps it would be possible to make the user focus on an invisible HTML textbox?

@chayleaf
Copy link

@linkpy maybe a better title would be something like "separate text input and game input"?

@cdaringe
Copy link

i think the intent is to add the capability to map input to physical keys vs virtual keys (KeyCode). i don't think window/UI text input is even part of this topic.

i'm a colemak user, but want WASD key mappings form motion, which on my keyboard is WARS. using KeyCode enum doesn't work for me. some games & engines handle this well. others, I must change keyboard layouts before game launch.

@linkpy
Copy link
Author

linkpy commented Feb 17, 2021

At no moment i mentioned text or IME input. It's exactly what @cdaringe said.
It's to have a layout-independent way to define keys.

@amadeusine
Copy link

I believe some form of scancodes is an important addition that many users can benefit from.
Would specific keyboard layouts/profiles be considered as custom definitions by Bevy users or within Bevy itself? I'm wondering whether there would have to be a minimum number of layout presets given that KeyCode would be used for mapping of virtual keys, if I understand this correctly.

@linkpy
Copy link
Author

linkpy commented Feb 17, 2021

There is no need to have layouts and all, everything is handled by the OS and SDL. The ScanCode is the key index pressed, the KeyCode is the translated key by the OS's keyboard manager.

@mattdm
Copy link

mattdm commented Mar 14, 2021

Another consideration: on my system (Fedora Linux 34 prerelease running GNOME with mostly the default keyboard layout), some keys don't have keycodes for ... some reason. These include Right Alt (scancode: 100, keycode: None) and Enter on the numeric keypad (scancode: 95, keycode: None).

(GNOME sets Right Alt to AltGr by default. No idea what's up with the keypad enter though.)

@maroider
Copy link

maroider commented Apr 7, 2021

There has been a lot of discussion about this specific issue, among other things, in rust-windowing/winit#753. There's also a meta-issue for keyboard input: rust-windowing/winit#1806.

Ultimately, it was decided that Winit will use enumeration names from the uievents-key and uievents-code specifications, with a couple of exceptions/additions, and I'd expect Bevy to benefit from adopting something similar. I think there may be something to be gained from having multiple projects converging around a single abstraction for this (like keyboard-types), but Winit is currently rolling its own enumerations and structs.

bors bot pushed a commit that referenced this issue Aug 5, 2022
# Objective

- I wanted to have controls independent from keyboard layout and found that bevy doesn't have a proper implementation for that

## Solution

- I created a `ScanCode` enum with two hundreds scan codes and updated `keyboard_input_system` to include and update `ResMut<Input<ScanCode>>`
- closes both #2052 and #862

Co-authored-by: Bleb1k <[email protected]>
inodentry pushed a commit to IyesGames/bevy that referenced this issue Aug 8, 2022
# Objective

- I wanted to have controls independent from keyboard layout and found that bevy doesn't have a proper implementation for that

## Solution

- I created a `ScanCode` enum with two hundreds scan codes and updated `keyboard_input_system` to include and update `ResMut<Input<ScanCode>>`
- closes both bevyengine#2052 and bevyengine#862

Co-authored-by: Bleb1k <[email protected]>
maccesch pushed a commit to Synphonyte/bevy that referenced this issue Sep 28, 2022
# Objective

- I wanted to have controls independent from keyboard layout and found that bevy doesn't have a proper implementation for that

## Solution

- I created a `ScanCode` enum with two hundreds scan codes and updated `keyboard_input_system` to include and update `ResMut<Input<ScanCode>>`
- closes both bevyengine#2052 and bevyengine#862

Co-authored-by: Bleb1k <[email protected]>
@targrub
Copy link
Contributor

targrub commented Oct 8, 2022

@linkpy Should this issue now be considered Closed?

james7132 pushed a commit to james7132/bevy that referenced this issue Oct 28, 2022
# Objective

- I wanted to have controls independent from keyboard layout and found that bevy doesn't have a proper implementation for that

## Solution

- I created a `ScanCode` enum with two hundreds scan codes and updated `keyboard_input_system` to include and update `ResMut<Input<ScanCode>>`
- closes both bevyengine#2052 and bevyengine#862

Co-authored-by: Bleb1k <[email protected]>
@james7132
Copy link
Member

This was added in #5495. Closing.

@alice-i-cecile
Copy link
Member

It's not an enum there: reopening :)

@maniwani
Copy link
Contributor

If/when rust-windowing/winit#2662 is merged upstream, there will be enums for both the physical location of a key and the semantic meaning of a keypress.

ItsDoot pushed a commit to ItsDoot/bevy that referenced this issue Feb 1, 2023
# Objective

- I wanted to have controls independent from keyboard layout and found that bevy doesn't have a proper implementation for that

## Solution

- I created a `ScanCode` enum with two hundreds scan codes and updated `keyboard_input_system` to include and update `ResMut<Input<ScanCode>>`
- closes both bevyengine#2052 and bevyengine#862

Co-authored-by: Bleb1k <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Input Player input via keyboard, mouse, gamepad, and more C-Feature A new feature, making something new possible
Projects
None yet
Development

No branches or pull requests