Skip to content

Keyboard Layout for Swedish #58

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

Merged

Conversation

PJ789
Copy link
Contributor

@PJ789 PJ789 commented Dec 7, 2021

.CPP file adds an ordinary Swedish keyboard layout.
.h file adds scancodes for the non-ascii characters commonly used on Swedish keyboards (a-ring etc).

@CLAassistant
Copy link

CLAassistant commented Dec 7, 2021

CLA assistant check
All committers have signed the CLA.

@github-actions
Copy link

github-actions bot commented Dec 7, 2021

Memory usage change @ 20f7498

Board flash % RAM for global variables %
arduino:avr:leonardo 0 - 0 0.0 - 0.0 0 - 0 0.0 - 0.0
arduino:sam:arduino_due_x_dbg 0 - 0 0.0 - 0.0 N/A N/A
arduino:samd:mkrzero 0 - 0 0.0 - 0.0 0 - 0 0.0 - 0.0
Click for full report table
Board examples/Serial
flash
% examples/Serial
RAM for global variables
%
arduino:avr:leonardo 0 0.0 0 0.0
arduino:sam:arduino_due_x_dbg 0 0.0 N/A N/A
arduino:samd:mkrzero 0 0.0 0 0.0
Click for full report CSV
Board,examples/Serial<br>flash,%,examples/Serial<br>RAM for global variables,%
arduino:avr:leonardo,0,0.0,0,0.0
arduino:sam:arduino_due_x_dbg,0,0.0,N/A,N/A
arduino:samd:mkrzero,0,0.0,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.

Nice to see more layouts coming! 😄 I do not use a Swedish layout myself, but just tried to review this based on pictures I found on the Internet, and on trying to set that layout on my computer. Please, tell me if I made any mistake.

@edgar-bonet
Copy link
Collaborator

Oh, I almost forgot. You should declare the layout in Keyboard.h:

--- a/src/Keyboard.h
+++ b/src/Keyboard.h
@@ -116,6 +116,7 @@ extern const uint8_t KeyboardLayout_en_US[];
 extern const uint8_t KeyboardLayout_es_ES[];
 extern const uint8_t KeyboardLayout_fr_FR[];
 extern const uint8_t KeyboardLayout_it_IT[];
+extern const uint8_t KeyboardLayout_sv_SE[];
 
 // Low level key report: up to 6 keys and shift, ctrl etc at once
 typedef struct

@per1234 per1234 added the type: enhancement Proposed improvement label Dec 8, 2021
@PJ789
Copy link
Contributor Author

PJ789 commented Dec 8, 2021

Oh, I almost forgot. You should declare the layout in Keyboard.h:

You are indeed right, and I had indeed done that for myself, but overlooked it.
Thanks Edgar.

@PJ789
Copy link
Contributor Author

PJ789 commented Dec 8, 2021

Nice to see more layouts coming! 😄 I do not use a Swedish layout myself, but just tried to review this based on pictures I found on the Internet, and on trying to set that layout on my computer. Please, tell me if I made any mistake.

Edgar thanks very much for your detailed review. I'll double check the few items indicated above. The Swedish keyboard has some ambiguous (to a non-Swede) symbols and some unusual features versus a more familiar keyboard.
The good news is that it is similar enough to Danish that, if we can get this going, I'm pretty confident I can do a Dansk version as well.

@github-actions
Copy link

github-actions bot commented Dec 8, 2021

Memory usage change @ cd9a30c

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

@edgar-bonet
Copy link
Collaborator

The Swedish keyboard has some ambiguous (to a non-Swede) symbols and some unusual features versus a more familiar keyboard.

You mean the dead keys at the top right which are used for diacritics? We have dead keys on the French, German and Spanish layouts as well.

@PJ789
Copy link
Contributor Author

PJ789 commented Dec 8, 2021

Are we done? How do we get this into the master branch?

@PJ789
Copy link
Contributor Author

PJ789 commented Dec 8, 2021

"Only those with write access to this repository can merge pull requests" ... anyone?

@edgar-bonet
Copy link
Collaborator

I tested this pull request (commit cd9a30c) with the following code:

#include <Keyboard.h>

extern const uint8_t KeyboardLayout_sv_SE[];

void setup() {
    Keyboard.begin(KeyboardLayout_sv_SE);
    delay(5000);
    Keyboard.print("<>\\|");
}

void loop(){}

I switched, on my PC, my keyboard layout to Swedish, then uploaded the sketch to my Arduino Micro, and a few seconds later the Arduino typed the following:

<{/€

This shows that:

  • 0x64 does work for <
  • 0x64|SHIFT does not work for >, it types { instead, as expected (see my comment).
  • 0x24|SHIFT does not work for \, it types / instead
  • 0x62|ALT_GR does not work for |, it types instead

Could you please run this sketch on your setup? If you get the same results, that would mean that at least the codes for >, \ and | should be fixed. For consistency, it wouldn't hurt to also fix <.

I ran the same test with the fixes I proposed and I got the correct result, namely <>\|.

@PJ789
Copy link
Contributor Author

PJ789 commented Dec 9, 2021

Using SWE layout I get same (<{/€). OK. I'll fix that (I have a SWE test keyboard handy).

@edgar-bonet
Copy link
Collaborator

Also, don't forget to declare the layout in Keyboard.h.

@PJ789
Copy link
Contributor Author

PJ789 commented Dec 9, 2021

OK... one difference... it works in my project code when I use Keyboard.press()
But not when I use keyboard.print().
Still investigating... but I think there may be some difference between the two methods...?

@edgar-bonet
Copy link
Collaborator

it works in my project code when I use Keyboard.press() but not when I use keyboard.print().

That should not make a difference. I modified my test sketch like this:

void setup() {
    Keyboard.begin(KeyboardLayout_sv_SE);
    delay(5000);
    Keyboard.press('<');  Keyboard.release('<');
    Keyboard.press('>');  Keyboard.release('>');
    Keyboard.press('\\'); Keyboard.release('\\');
    Keyboard.press('|');  Keyboard.release('|');
}

and got the same result: <{/€.

@PJ789
Copy link
Contributor Author

PJ789 commented Dec 9, 2021

My suspicion at the moment is that Keyboard.press('<') plus a separate keyboard SHIFT modifier keypress works... which is how my current project functions (and that is fine).

Where as Keyboard.press('>') lookup in KeyboardLayout_sv_SE returning 0x64|SHIFT as a single code, attempting to send that combo (which might relate to the comment in KeyboardLayout.h ("The exception is 0x64, the key next next to Left Shift on the ISO layout (and absent from the ANSI layout). We handle it by replacing its value by 0x32 in the layout arrays.")

Which you did highlight, and I didn't understand... but now I still don't understand... but can see is relevant. I will try using 0x32 and see if that solves it :)

@PJ789
Copy link
Contributor Author

PJ789 commented Dec 9, 2021

OK, its fixed, this code was used to test;

`#include <Keyboard.h>

extern const uint8_t KeyboardLayout_sv_SE[];

void setup() {
Keyboard.begin(KeyboardLayout_sv_SE);
delay(5000);
Keyboard.press('<'); Keyboard.release('<');
Keyboard.press('>'); Keyboard.release('>');
Keyboard.press('\'); Keyboard.release('\');
Keyboard.press('|'); Keyboard.release('|');
Keyboard.print("<>\|");
}

void loop(){}`

And yields the right results now. I'll fix the sv_SE layout.

PJ789 and others added 4 commits December 9, 2021 14:30
Confirmed correct combination for bslash

Co-authored-by: Edgar Bonet <[email protected]>
@PJ789
Copy link
Contributor Author

PJ789 commented Dec 9, 2021

Hi Edgar...

thank you. I believe all queries are resolved, your contributions were quite correct.

Thank you very much for your help & review.

Are you able to commit this contribution to the master branch now?

regards
Pete.

@github-actions
Copy link

github-actions bot commented Dec 9, 2021

Memory usage change @ 28735fd

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

@edgar-bonet
Copy link
Collaborator

Hi Pete!

I do not have write access to this repository. I am just the contributor who implemented the support for multiple keyboard layouts, and the layouts fr_FR, it_IT, de_DE and es_ES (c.f. PR #53). This is why I am very glad to help others expand this support.

BTW, do not forget to add your layout to Keyboard.h.

@PJ789
Copy link
Contributor Author

PJ789 commented Dec 9, 2021

Thanks again Edgar, a revised keyboard.h is also attached now.

I hope someone will merge this pull request for us?

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.

Looks good to me.

@github-actions
Copy link

github-actions bot commented Dec 9, 2021

Memory usage change @ c62a5c7

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

@PJ789
Copy link
Contributor Author

PJ789 commented Dec 9, 2021

Hi @agdl ..
I hope I've done the right thing. I've 'assigned' this PR to you, in the hope you could merge his enhancement that Edgar & myself have created... adding support for Swedish keyboards/scancodes to Keyboard.
regards
Pete

@PJ789
Copy link
Contributor Author

PJ789 commented Dec 9, 2021

@facchinm are you able to merge this enhancement that Edgar & myself have created adding support for Swedish keyboards/scancodes to Keyboard?
regards
Pete

@facchinm
Copy link
Contributor

Since it's been approved by @edgar-bonet I'm squashing and merging it 🙂
Thanks for your contribution!

@facchinm facchinm merged commit fbf472f into arduino-libraries:master Dec 10, 2021
@PJ789 PJ789 deleted the Swedish-keyboard/language-support branch December 26, 2021 15:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement Proposed improvement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants