Digistump Forums

The Digispark => Digispark (Original) Support => Topic started by: Cromewell on December 16, 2016, 12:36:57 pm

Title: Rewrite the DigiKeyboard library
Post by: Cromewell on December 16, 2016, 12:36:57 pm
Hey there!
It's really annyoing that I'm not able to use the digispark stick properly, because I use a german keyboard.
So I wanted to ask, if someone (or even a group) feels like rewriting the library so it works (no matter which keyboard layout)?
I will try it on my own, but I only know Java pretty well, not C. So yeah.
Tell me what you think about it.


Have a nice day :)
Title: Re: Rewrite the DigiKeyboard library
Post by: rebane2001 on December 19, 2016, 08:00:26 am
A semi-fix for it is to set your keyboard layout to US, but type out what you want to type as if you were using your own layout's keyboard
That way it will press the correct characters
Title: Re: Rewrite the DigiKeyboard library
Post by: Cromewell on December 19, 2016, 09:58:27 am
Yeah...That's the way I did it 'til now. The problem with that typing method(american layout but the chars I want) is, that the chars which this method is producing are (most of them) not convertable for the algorithm used to convert a char to keycode. So it is not working. I already wrote a program days ago, which converts the chars into the equavalent american char, but yeah, the problem is the converting algo.
Title: Re: Rewrite the DigiKeyboard library
Post by: MaMe82 on February 07, 2017, 04:53:32 am
I finally have rewritten DigiKeyboardDevice.h to use a different Keyboard Layout, but found a far better solution in the end.

The problem with "DigiKeyboardDevice.h" is that it uses a ASCII translation table to make DigiKeyboard.println() and DigiKeyboard.print() work.
The translation table could be found in scancode-ascii-table.h and has a major problem. The most significant bit is used to encode the SHIFT modifier key (for example to send an 'A' instead of an 'a' via USB).

Now the problem is that other keyboard layouts use additional modifier keys (like ALT GR in German keyboard layout) to change the scancodes.

Implementing the capability of using different modifier keys ended up in rewriting the whole DigiKeyboarDevice.h file for a single layout, which I had done for German layout (Teensy Keyboard implementation is a good starting point).

Another issue is, that println() / print() seems to send UTF-8 key codes to the "void write(uint8_t)", but due to ASCII conversations all characters outside printable ASCII keyspace are ignored.

Thus I have thrown away my attempts to "hack" DigiKeyboardDevice.h and came up with a much simpler solution, based on DuckEncoder, which already handles the keyboard language layout for us:

https://github.com/mame82/duck2spark (https://github.com/mame82/duck2spark)

The solution comes with the free benefit of dealing with string size limitation due to low amount of avaiulable RAM on DigiSpark
Title: Re: Rewrite the DigiKeyboard library
Post by: Fardenco on February 18, 2017, 04:55:06 pm
I faced the same problem but I've found a quite simple way to use altgr modifier, in fact the second most significant bit is alway at 0 for keyboard characters, so I simply did the same thing as for shift with the 1st msb, but with altgr with the 2nd msb.
You can find the modified files here
https://github.com/digistump/DigistumpArduino/issues/46
They are for azerty layout, but I suppose they could easily be modified for any other layout that need altgr
Title: Re: Rewrite the DigiKeyboard library
Post by: MaMe82 on February 20, 2017, 02:31:39 pm
Nice solution, but I didn't used this bit for a reason (commented here: https://github.com/digistump/DigistumpArduino/issues/46#issuecomment-281197162 (https://github.com/digistump/DigistumpArduino/issues/46#issuecomment-281197162))
Title: Re: Rewrite the DigiKeyboard library
Post by: Cromewell on June 16, 2017, 01:48:07 pm
Hey :) Just saw this post and tried https://github.com/mame82/duck2spark out - it's working fine! Thanks for sharing!!