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

Adding full ASCII support #1

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

technologicalMayhem
Copy link

I changed up the code for converting the keys returned by evdev to actual chars. It now takes holding down shift into account, so that upper-case is possible. Also I added in some missing character to allow full support of all printable ASCII characters minus DEL (so character code 32-126).

Also I bumped the version number.

Copy link
Member

@de-vri-es de-vri-es left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the PR!

I think it's a nice addition to support full ASCII. Personally, I think it would even be okay to insert BACKSPACE and DEL characters. If they actually appear on a barcode, then why not put them in the resulting string?

Of course, there are still ASCII characters without a corresponding key. It might be interesting to see what barcode scanners do when they read them. However, I don't think this needs to be done for this PR :)

Cargo.toml Outdated Show resolved Hide resolved
src/lib.rs Outdated Show resolved Hide resolved
src/lib.rs Show resolved Hide resolved
src/lib.rs Show resolved Hide resolved
@technologicalMayhem
Copy link
Author

I though about adding in DEL and BACKSPACE but placing them in a barcode returns a different set of keys being pressed by the scanner, depending on what barcode format I used. So that suggests to me that putting them in a barcode might be undefined behavior, or might be handled differently depending on the barcode spec.

@de-vri-es
Copy link
Member

I though about adding in DEL and BACKSPACE but placing them in a barcode returns a different set of keys being pressed by the scanner, depending on what barcode format I used. So that suggests to me that putting them in a barcode might be undefined behavior, or might be handled differently depending on the barcode spec.

Yeah, not all barcode formats support the full ASCII range. I'm fine with ignoring them now. If it makes sense we can always handle them later.

match key_name {
evdev::Key::KEY_LEFTSHIFT => left_shift_pressed = event.value() == 1,
evdev::Key::KEY_RIGHTSHIFT => right_shift_pressed = event.value() == 1,
evdev::Key::KEY_CAPSLOCK => capslock_on = event.value() == 1,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this correct? Does an evdev device report a key-up the second time you press capslock?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like capslock is reported as usual: press and release events match the actual key state. Not the "is capslock enabled" bit.

If I use a real keyboard, I do receive LED events. It may be some other components doing that: the Xorg server or the Wayland compositor. But that's fine. I think we should just follow the LED events and not look at the KEY_CAPSLOCK events.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although maybe this isn't true when you have an exclusive grab.. Hmm..

Maybe we should just ignore capslock support entirely.. Sorry for the turmoil.. What do you think?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would just say to drop it. Caps lock working differently to pressing shift would require more complexity in handling it anyway.

Also to my understanding the LED events come from whatever is handling the keyboard. The keyboard is not responsible for tracking the LED states, usually Xorg or a Wayland compositor.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, sounds good to me. I highly doubt barcode scanners would use capslock anyway. And if they do they shouldn't >.<


// Map key_name to the number or char.
if event.value() == 1 {
if let Some(c) = key_to_str(key_name, left_shift_pressed || right_shift_pressed || capslock_on) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't totally correct: capslock only shifts letters to their uppercase variant. It doesn't shift numbers or symbols.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants