Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 11 of 11

Thread: Teensy write key by key, UTF-8

  1. #1
    Junior Member
    Join Date
    Nov 2017
    Posts
    9

    Teensy write key by key, UTF-8

    Hello,

    I try to write key by key, with the Teensy 3.2.

    For example, if i have three push buttons, and each have an assigned key, i would like that when i push on the first one, for exemple, it outputs "Ծ", the second, "ݑ", etc.

    So, i would like to send UTF-8 chars to be written on the computer as if it was a keyboard that was typing.
    But i don't know the Teensy very well, and i don't know if it's the OS keyboard layout that rules the characters, or can we write char by char, like this, as if we had a keyboard with every UTF-8 keys ?

    Thanks.

  2. #2
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    17,051
    You're asking about using Teensy as a USB Keyboard, right? Or maybe something else? I'm having a difficult time to fully understand your question.

  3. #3
    Junior Member
    Join Date
    Nov 2017
    Posts
    9
    I'm trying to use the Teensy as a USB Keyboard, and writing UTF-8 characters

    But in the All Keys Codes section, there's only a few characters avaible to print.

  4. #4
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    17,051
    Teensy can only "type" the same characters you are able to type on a regular USB keyboard.

    The USB Keyboard protocol communicates which physical keys are pressed. It is NOT anything like Unicode or UTF8.

    Keyboard.print() tries to decode UTF8, according to the setting you have in Tools > Keyboard Layout. But it is only able to translate UTF8 for known key combinations and sequences for the layout you have chosen. The USB keyboard protocol is only physical keys, not Unicode chars.

  5. #5
    Junior Member
    Join Date
    Nov 2017
    Posts
    9
    Ho, ok. Thank for the clarification.

    So, if i want some special characters, the best thing i have to do is to create a Keyboard Layout in my OS, so Teensy simulated keystrokes output characters that match in the OS's keyboard layout.
    And create a custom keyboard layout in https://github.com/PaulStoffregen/co...3/keylayouts.h for having more consistence in the code, but that's optional.
    Last edited by Minege; 11-05-2017 at 01:19 AM. Reason: adding more info

  6. #6
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    17,051
    Which layout does your OS use?

    I implemented all of the ones which were well documented.

  7. #7
    Junior Member
    Join Date
    Nov 2017
    Posts
    9
    I mean that if we want to write very special characters, we can create an OS keyboard layout that contain theses characters and use the layouts in the teensy that you implemented (for exemple QWERTY) to match the keys that you want in your OS layout.
    For exemple, if you want an x character in your computer, you create the OS layout that contain the x on the "C" letter of qwerty, and for typing x, you Keyboard.press(KEY_C) using the QWERTY teensy layout, etc..

  8. #8
    Junior Member
    Join Date
    Nov 2017
    Posts
    9
    Tho, i would need to have more keys than the avaible keys on a keyboard, so i thought of switching to more special-layout when you need to "type" this key, for exemple typing SHIFT+ALT, "typing" your special key, and then SHIFT+ALT and coming back to the original OS keyboard layout to continue "typing". But, this wouldn't work on a computer without a Window Manager. So, i thought that the teensy send serial data to your program running in background, and your program send keys to the OS, and so, you can send any keys. But i don't know if that would be slower that the USB Keyboard protocol. I think so, because there's more layers before your key is typed. (Teensy->Serial->Software->Send keystroke) (Teensy simulating usb keyboard->OS Layout receiving keystroke and doing it)

  9. #9
    Quote Originally Posted by PaulStoffregen View Post
    Which layout does your OS use?

    I implemented all of the ones which were well documented.
    Hi Paul

    Is there a quick way to see which key's are the same on almost all layouts and which combinations have a special meaning on several Os'es?

    This to get a set of key's (on the keyboard) that give always the same code to the application and don't have a special meaning.

    Alain

  10. #10
    Junior Member
    Join Date
    Nov 2017
    Posts
    9
    Sorry, i wasn't very clear.

    I would like the Teensy to "type" characters that can be on the qwerty layout or not, and that's it.
    For example, type "a", and then, type "".

    I thought of doing a software that emulate keys when he receive data over serial usb, but i think that's slow.
    I also thought of a custom OS layout that make a lot of keys when you do, for example, SHIFT+ALT+A, that give , but then again, if i want to do SHIFT+ALT+A, as a key binding for exemple, it will output "", and so if i really want to write "", it will activate the key binding.

  11. #11
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    17,051
    Quote Originally Posted by Minege View Post
    I mean that if we want to write very special characters, we can create an OS keyboard layout that contain theses characters
    I do not know. I have never attempted to create a custom keyboard layout on any operating system. I do not even know if this is possible on Windows and Macintosh, whether users can do this or if it's a feature only Microsoft & Apple can control.

    Quote Originally Posted by AlainD View Post
    Is there a quick way to see which key's are the same on almost all layouts and which combinations have a special meaning on several Os'es?
    When I created the set of layouts for Teensyduino, I mostly used an older version of this Microsoft documentation (the old site seems to be gone), and a couple wikipedia pages.

    Many other websites exist with info about keyboard layouts. I have not looked at most of them. If you find a really good one for this purpose, please share.

    There are a few complexities to keep in mind with keyboard layouts, which make everything much more difficult...

    1: Most non-US keyboards uses the right side Alt key to assign a 3rd character to many keys. On US keyboards every key does only 2 things, depending on whether you press the shift key. But 3 or even 4 functions (Alt + Shift) are common for other layouts.

    2: Many non-US layouts use "dead key" sequences, usually for typing seldom-used accents. So the character depends not only on the key plus a modifier held, but the sequence of which key you previously pressed. For example, on the French Canadian keyboard, to type "", you first press the "]" key and then press "u". You don't hold it while pressing "u", you actually press and release them in sequence to achieve a single character typed.

    3: The worst problem of all are the completely alternate layouts, like Cyrillic chars used by Russian language. Using these requires vision of the screen or knowledge of the PC's settings, which obviously Teensy doesn't have. Humans with these keyboards actually switch their OS setting to remap the entire keyboard between the alternate character sets as they type. This system fundamentally relies on the person remembering which mode they currently have selected, or looking at a visual indication on their screen if they are unsure, or just typing a couple keystrokes and visually noticing they are from the other layout. Worst of all, the user input toggles between the sets, which works well for humans with eyesight and short term memory, so there isn't any well defined input Teensy can send that puts the OS into a particular mode. Being able to toggle or cycle modes doen't help if you don't know the current mode and have no way to observe as you send the keystrokes.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •