Skip to content

Ability to use right alt aka. alt gr to reach all characters on non us/uk layouts #50

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

Closed
wants to merge 2 commits into from

Conversation

nuuttihenriksson
Copy link

Simply added possibility for non us/uk keyboards to reach characters.

Uses only libraries that were already included.

@CLAassistant
Copy link

CLAassistant commented Sep 13, 2021

CLA assistant check
All committers have signed the CLA.

@github-actions
Copy link

Memory usage change @ 7152246

Board flash % RAM for global variables %
arduino:avr:leonardo 🔺 +254 - +254 +0.89 - +0.89 0 - 0 0.0 - 0.0
arduino:sam:arduino_due_x_dbg 🔺 +168 - +168 +0.03 - +0.03 N/A N/A
arduino:samd:mkrzero 🔺 +160 - +160 +0.06 - +0.06 0 - 0 0.0 - 0.0
Click for full report table
Board examples/Serial
flash
% examples/Serial
RAM for global variables
%
arduino:avr:leonardo 254 0.89 0 0.0
arduino:sam:arduino_due_x_dbg 168 0.03 N/A N/A
arduino:samd:mkrzero 160 0.06 0 0.0
Click for full report CSV
Board,examples/Serial<br>flash,%,examples/Serial<br>RAM for global variables,%
arduino:avr:leonardo,254,0.89,0,0.0
arduino:sam:arduino_due_x_dbg,168,0.03,N/A,N/A
arduino:samd:mkrzero,160,0.06,0,0.0

Copy link
Collaborator

@edgar-bonet edgar-bonet left a comment

Choose a reason for hiding this comment

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

AltGr is already usable as

Keyboard.press(KEY_RIGHT_ALT);

How would this change make it easier? How would you use the new feature? It is not visible through the library API.

x &= 0x7F;
k = (uint8_t)x;
} else if(x & 0x100) { // it's a character reached with alt gr aka. right alt
_keyReport.modifiers |= 0x05; // alt gr aka. right alt modifier
Copy link
Collaborator

Choose a reason for hiding this comment

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

You mean

_keyReport.modifiers |= 0x40;

i.e.

_keyReport.modifiers |= (1<<(KEY_RIGHT_ALT-128));

@nuuttihenriksson
Copy link
Author

AltGr is already usable as

Keyboard.press(KEY_RIGHT_ALT);

How would this change make it easier? How would you use the new feature? It is not visible through the library API.

I have added the alt gr as a modifier that can be applied to the ascii map. This means that instead of having to break up print commands because of characters such as /{}$€, they are managed through the ascii map in the .cpp file.

This makes the library a lot more usable for people with keyboard layouts other than english.

As I said I implemented it in the Keyboard.cpp file. The asciimap as well as the memory map has been changed to 16bits to fit an extra check bit (as was done with shift modifier).

The shift modifier had the eith bit set as 1. Alt gr uses ninth bit set as 1. In addition to the 8bit -> 16bit change I also had to use memcpy_P to copy the number from the ascii map.

This change includes no new libraries and does not require a significant amount of resources.

@edgar-bonet
Copy link
Collaborator

I have added the alt gr as a modifier that can be applied to the ascii map.

But you have not modified the ASCII map, so it would seem the change serves no purpose. Or maybe you expect the users to modify the ASCII map themselves?

characters such as /{}$€

/, {, } and $ are ASCII characters, but is not, thus it cannot fit in the ASCII map.

Furthermore, most computers nowadays use UTF-8 encoding for files, and “€” is then encoded as a sequence of three bytes: 0xe2, 0x82 and 0xac. It is not a “character” in the C++ sense (a char), meaning that

Keyboard.write('');

is not valid C++, and

Keyboard.print("");

would attempt to print three characters. In this case they happen to be all invalid, but printing "ó" for example (UTF-8: 0xc3, 0xb3) will be interpreted as KEY_F2 followed by KEY_TAB.

Thus I ask again the same question: How would you use this new feature?

@nuuttihenriksson
Copy link
Author

I have added the alt gr as a modifier that can be applied to the ascii map.

But you have not modified the ASCII map, so it would seem the change serves no purpose. Or maybe you expect the users to modify the ASCII map themselves?

characters such as /{}$€

/, {, } and $ are ASCII characters, but is not, thus it cannot fit in the ASCII map.

Furthermore, most computers nowadays use UTF-8 encoding for files, and “€” is then encoded as a sequence of three bytes: 0xe2, 0x82 and 0xac. It is not a “character” in the C++ sense (a char), meaning that

Keyboard.write('');

is not valid C++, and

Keyboard.print("");

would attempt to print three characters. In this case they happen to be all invalid, but printing "ó" for example (UTF-8: 0xc3, 0xb3) will be interpreted as KEY_F2 followed by KEY_TAB.

Thus I ask again the same question: How would you use this new feature?

My bad. I was not suppose to include '€'. For example if I want to do print("C:\Users\Randomuser\Desktop"); I would have to do
Keyboard.print("C:");
Keyboard.press(KEY_RIGHT_ALT);
Keyboard.press(what ever the hex is for plus);
Keyboard.releaseAll();
Keyboard.print("Users");
...

When the alt gr / right alt is added into the code I can just print the line without any problems.

@nuuttihenriksson
Copy link
Author

What is the status on this?

@per1234
Copy link
Contributor

per1234 commented Mar 6, 2022

@nuuttihenriksson @edgar-bonet was this superseded by #53?

@per1234 per1234 added status: waiting for information More information must be provided before work can proceed topic: code Related to content of the project itself type: enhancement Proposed improvement labels Mar 6, 2022
@nuuttihenriksson
Copy link
Author

nuuttihenriksson commented Mar 6, 2022

@nuuttihenriksson @edgar-bonet was this superseded by #53?

Good points by @edgar-bonet, was just an early idea. #53 looks good.

@per1234 per1234 added conclusion: duplicate Has already been submitted and removed status: waiting for information More information must be provided before work can proceed labels Mar 6, 2022
@per1234
Copy link
Contributor

per1234 commented Mar 6, 2022

Thanks for your speedy response, and for your contribution @nuuttihenriksson!

Regards, Per

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
conclusion: duplicate Has already been submitted topic: code Related to content of the project itself type: enhancement Proposed improvement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants