how générate keyboard key "<" and ">" ?

Hi all,

I design with IDE arduino and teensy LC

i would like design à keyboard custum for me, I need the key "<" and ">", i used keyboard azerty,
when i try this:

     if (key == '*') {
              Keyboard.write(60);
       Keyboard.send_now();
    }

in table ascii 60 , i read touche "<", but I have a key "." (point).

I try this:

/*
  ASCII table

 Prints out byte values in all possible formats:
 * as raw binary values
 * as ASCII-encoded decimal, hex, octal, and binary values

 For more on ASCII, see http://www.asciitable.com and http://en.wikipedia.org/wiki/ASCII

 The circuit:  No external hardware needed.

 created 2006
 by Nicholas Zambetti
 modified 9 Apr 2012
 by Tom Igoe

 This example code is in the public domain.

 <http://www.zambetti.com>

 */
void setup() {
  //Initialize serial and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }

  // prints title with ending line break
  Serial.println("ASCII Table ~ Character Map");
}

int thisByte = 33;
// you can also write ASCII characters in single quotes.
// for example. '!' is the same as 33, so you could also use this:
//int thisByte = '!';

void loop() {
  // prints value unaltered, i.e. the raw binary version of the
  // byte. The serial monitor interprets all bytes as
  // ASCII, so 33, the first number,  will show up as '!'
  Keyboard.write(thisByte);
  delay(100);
    Keyboard.println(" ");
  delay(100);

  Serial.print(", dec: ");
  // prints value as string as an ASCII-encoded decimal (base 10).
  // Decimal is the  default format for Serial.print() and Serial.println(),
  // so no modifier is needed:
  Serial.print(thisByte);
  // But you can declare the modifier for decimal if you want to.
  //this also works if you uncomment it:

  // Serial.print(thisByte, DEC);


  Serial.print(", hex: ");
  // prints value as string in hexadecimal (base 16):
  Serial.print(thisByte, HEX);

  Serial.print(", oct: ");
  // prints value as string in octal (base 8);
  Serial.print(thisByte, OCT);

  Serial.print(", bin: ");
  // prints value as string in binary (base 2)
  // also prints ending line break:
  Serial.println(thisByte, BIN);


  // if printed last visible character '~' or 126, stop:
  if (thisByte == 128) {    // you could also use if (thisByte == '~') {
    // This loop loops forever and does nothing
    while (true) {
      continue;
    }
  }
  // go on to the next character
  thisByte++;
}

this is the result in notepad:

ù 
9 
0 
8 
+ 
; 
) 
! 
é 
" 
' 
( 
- 
è 
_ 
ç 
M 
m 
. ù 
9 
0 
88 
+ 
; 
) 

= 
/ 
§ 
2 
B 
F 
G 
H 
I 
J 
K 
L 
? 
N 
O 
A 
U 
V 
Z 
X 
Y 
W 
^
* 
$ 
6 
° 
² 
q 
b 
c 
e 
i 
j 
k 
l 
, 
o 
s 
t 
u 
v 
z 
x 
y 
w 
¨
µ 
£

Where is key "<" and ">" ??? :disappointed_relieved:

How i cant générate these key ? is it possible ?

The keyboard commands with teensy, leonardo and micro are NOT based on ASCII.
The command is based on the standard US keyboard.

What a keyboard transmits is NOT characters/letters (like "a", "q", "1") but "key presses" of a standard US keyboard. How this key press is interpreted is based on the language settings of your operating system.

Example: the keyboard "says": the second key (starting from left) in third row (starting from bottom) has been pressed. On many keyboards this is letter "a", so this is easy :slight_smile:

It becomes tricky when you like to get characters like "<" or ">" because they can be on different keys, depending on the keyboard layout of your country/language.

At the US standard keyboard characters "<" and ">" are on the keys just right to the key "M".
But on my German QWERTZ keyboard right to the key "M" there are "," and ".".
On your French (?) AZERTY keyboard there might be "," and ";".

To get the charakter "<" with your language settings try to use

Keyboard.print(",");

to get the charakter ">", try to use

Keyboard.print(";");

thank for help me I 'm friench in france

I try this

void setup() {
  //Initialize serial and wait for port to open:
  Serial.begin(9600);
 
  // prints title with en 
  Serial.println("ASCII Table ~ Character Map");
}

// first visible ASCIIcharacter '!' is number 33:
int thisByte = 60;
// you can also write ASCII characters in single quotes.
// for example. '!' is the same as 33, so you could also use this:
//int thisByte = '!';

void loop() {
  // prints value unaltered, i.e. the raw binary version of the 
  // byte. The serial monitor interprets all bytes as
  // ASCII, so 33, the first number,  will sho upre(thisByte);
    Serial.println(thisByte);
  //Keyboard.press(thisByte); Keyboard.release(thisByte);
     Keyboard.print("a");
  delay(1000);
   Keyboard.print(",");
  delay(1000);
  Keyboard.print(";");
  delay(1000);
}

this cap lock

MQ.M.MQMQ

without cap lock

mq;m;mq;

I didn't know lib arduino léonardo is not ACII

Run this sketch:

Ray

     if (key == '*') {

Keyboard.write(60);
      Keyboard.send_now();
    }




in table ascii 60 , i read touche "<", but I have a key "." (point).

Suppose you make a loop that writes and sends the keyboard all possibilities and see what you get?

the problème in console sérial is ok

//thisByte => 60
  Serial.print(", dec: ");
  // prints value as string as an ASCII-encoded decimal (base 10).
  // Decimal is the  default format for Serial.print() and Serial.println(),
  // so no modifier is needed:
  Serial.print(thisByte);

but in keyboard.write(60) is not a "<" but "."

I scan all key, there note key < here in note pad with this script

/*
  ASCII table

 Prints out byte values in all possible formats:
 * as raw binary values
 * as ASCII-encoded decimal, hex, octal, and binary values

 For more on ASCII, see http://www.asciitable.com and http://en.wikipedia.org/wiki/ASCII

 The circuit:  No external hardware needed.

 created 2006
 by Nicholas Zambetti
 modified 9 Apr 2012
 by Tom Igoe

 This example code is in the public domain.

 <http://www.zambetti.com>

 */
void setup() {
  //Initialize serial and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }

  // prints title with ending line break
  Serial.println("ASCII Table ~ Character Map");
}

// first visible ASCIIcharacter '!' is number 33:
int thisByte = 32;

void loop() {
    Keyboard.write(thisByte); delay(100); Keyboard.println("");
  
  Serial.write(thisByte);
delay(100);
  Serial.print(", dec: ");

  Serial.print(thisByte);

  Serial.print(", hex: ");
  // prints value as string in hexadecimal (base 16):
  Serial.print(thisByte, HEX);

  Serial.print(", oct: ");
  // prints value as string in octal (base 8);
  Serial.print(thisByte, OCT);

  Serial.print(", bin: ");
  // prints value as string in binary (base 2)
  // also prints ending line break:
  Serial.println(thisByte, BIN);

  // if printed last visible character '~' or 126, stop:
  if (thisByte == 126) {    // you could also use if (thisByte == '~') {
    // This loop loops forever and does nothing
    while (true) {
      continue;
    }
  }
  // go on to the next character
  thisByte++;
}

In the red is capital lock note pad

http://hpics.li/81da597

You show the serial output where '<' is 60 dec

Now try with keyboard.write instead of serial.write just to see what you get.

Something like this, just to see what comes out.

void setup()
{
keyboard.begin();

for ( byte k = 32; k < 127; k++ )
{
keyboard.write( k );
keyboard.write( '\n' );
}
}

void loop()
{
}

It is much dependent on the operating system country/language settings.

As much as I found out it is pretty difficult to "produce" < or > if you have country/language settings like German or French.
If so, even

for (int i=32; i<128; i++)
{   Keyboard.write(i);
}

will not bring any result of "<" or ">" IF your country/language settings are like German or French.

Background
This is my (German) keyboard:
my_gr_keyboard.jpg
You can see the < and > is on a "special" key just right of the shift key.
This physical key is not present on the "standard US keyboard".

As much as I understand: the HID keyboard emulation of leonardo / micro / teensy is dependent on HID.cpp.

There you can find an array "_asciimap" where the ASCII codes are converted to scancodes. Scancodes are some kind of "key presses" of a keyboard: what physical key is pressed to "produce" a certain character/letter/symbol.

The special thing with this _asciimap in "HID.cpp" is that - as much as I understand - it is based on the standard US keyboard layout. But the _asciimap lookup does not "have" this special key, you can see on the picture of my keyboard because this physical key it is not present on a standard US keyboard.

Solution (at least for me/my settings)
You can adjust the scancodes for < and > in the HID.cpp to meet your needs (the needs of your keyboard / country/language settings).

The tricky thing: there may be more than one version of HID.cpp on your hard disk but only one is relevant. It depends on Arduino IDE version, operating system and maybe more.
So you can make a search for HID.cpp and edit all of the files (but make a backup copy first).

In HID.cpp search for the _asciimap array and find:

    0x25,          // 8
    0x26,          // 9
    0x33|SHIFT,    // :
    0x33,          // ;
    0x36|SHIFT,    // <  ORIGINAL
    0x2e,          // =
    0x37|SHIFT,    // >  ORIGINAL
    0x38|SHIFT,    // ?

Change to :

    0x25,          // 8
    0x26,          // 9
    0x33|SHIFT,    // :
    0x33,          // ;
    0x64,          // <  MODIFICATION
    0x2e,          // =
    0x64|SHIFT,    // >  MODIFICATION
    0x38|SHIFT,    // ?

Tank's it true,

This physical key is not present on the "standard US keyboard".

my keyboard azerty "< > "is near w.

I try modifie

C:\Program Files (x86)\Arduino\hardware\arduino\cores\arduino\HID.cpp

but is not effetc,
I fond another HID.cpp in

C:\Program Files (x86)\Arduino\hardware\arduino\cores\arduino

now I try is the modify is effect effect

I try with code get me

void setup()
{
  Keyboard.begin();

  for ( byte k = 32; k < 127; k++ )
  {
    Keyboard.write( k );
    delay(100);
    Keyboard.write( '\n' );
    delay(100);

  }
}

void loop()
{
}

this is a result

9
0+
;
)
:
!
&

(
-
è
_
çm
.
§
2
Q
B
C
D
E
F
G
H
J

N
O
P
A
R
T

X
Y
W
^
*
$
6
°
²
q
b
c
d
e
f
h

l
,
n
o
p
a
r
s
t
u
v
z
x
y
w
¨
µ
£

I must reboot windows for HID.cpp refresh ?

the position line code is it imporant ?

exemple

	0x64,      // <
	0x2e,          // =
    0x64|SHIFT,    // >  MODIFICATION
	0x37|SHIFT,      // >

is equal ? order is important ?

	0x33,          // ;
	0x2e,          // =
	0x64,      // <
        0x64|SHIFT,    // >  MODIFICATION

edit:

I don't understant if HID.cpp is valide in my system.
I try this in HID folder arduino and robot:

const uint8_t _asciimap[128] =
{
 //delte all ligne, only del is no delted
	0				// DEL
};

I load in teensy , i reboot window but all caractère is here ???

I try find another HID in my C:/, but i not have another file HID.cpp,
We can send only this 2 caractère > & < without lib arduino ? or is to difficult ?

I am sorry that I could not help you so far.
The procedure above works with Arduino Leonardo and Arduino Micro, but may not with Teensy boards.

I have used several Teensy boards in the past for different projects, but have not used Teensy during the last years (and my recollection is not so clear). So I was searching for one of my Teensies and I found one, far back in the drawer :slight_smile:
(By the way it is a Teensy++ 2.0 - I do not have a Teensy LC).
And I got the latest Teensyduino add-on (1.29) for the Arduino IDE (I use 1.6.5-r5) and installed it.

I plugged in the Teensy board and launched the Arduino IDE.
In the tools menu, I selected ...

  • the right board (mine is Teensy++ 2.0)
  • USB-Type: Keyboard + Mouse + Joystick

In the next row of the menu I found "Keyboard Layout" and a long list with entries like German, French, Italian, Swedish and many more.

I activated "German".
I uploaded this simple code example:

void setup() {
  Keyboard.begin();
  delay(5000);
  Keyboard.println("Hello World ");
  for (int j=32; j<128; j++)
  {   Keyboard.print(j);
      Keyboard.print(" ");
      Keyboard.write(j);
      Keyboard.println();   
      delay(100);
  }
}

void loop() {
}

And I got all expected ASCII characters.
< is number 60

is number 62

With my setup (German language settings on PC) it does not work very well with different keyboard layout settings than "German", but that is what I expected.

It seems to be pretty easy to work with Teensy as a keyboard.

So my questions are (and I should have asked them before):

  • What Arduino IDE version do you use?

  • Have you "installed" the Teensyduino add-on for the Arduino IDE (website)

  • Did you select the proper menu items (Teensy board, USB Type, Keyboard Layout)?

I used old IDE arduino, because a new version arduino (1.06) il not compatible.

I used teensdinio 1.29

http://hpics.li/c23c4f9

My project is have build 2 keyboard with + 2 teensy LC + 1 hub USB with 2 port USB

1 -right keyboard with 70 key
2 - left keyboard with 70 key

I think juste 1 teensy in enought?
préaps if i buy a teensy 3++

https://www.pjrc.com/store/teensy32.html

I resolve to find all key ?
Is it enought with only 1 teensy 3+ have 140 keyboard + 4 bit reserve input ?
I try with teensy LC can 12 bit X 12 bit combinaison key.

Or to abondanne 1 teensy ang keep old controller true keyboard usb (azerty).
This solution is easy to keep à key, but preaps , the solder wire is none order between keyboard left and right and difficult sold layout pcb because is to tiny .... :cold_sweat:

this is result your code

Hello Zorld 
"é  
"" 1
"' %
"( 3 
"- 4
"è 5
"_ 7
"ç ù
'à 9
'& 0
'é 8
'" +
'' ;
'( )
'- :
'è !
'_ à
'ç &
(à é
(& "
(é '
(" (
(' -
(( è
(- _
(è ç
(_ M
(ç m
-à .
-& =
-é /
-" §
-' 2
-( Q
-- B
-è C
-_ D
-ç E
èà F
è& G
èé H
è" I
è' J
è( K
è- L
èè ?
è_ N
èç O
_à P
_& A
_é R
_" S
_' T
_( U
_- V
_è Z
__ X
_ç Y
çà W
ç& ^
çé *
ç" $
ç' 6
ç( °
ç- ²
çè q
ç_ b
çç c
&àà d
&à& e
&àé f
&à" g
&à' h
&à( i
&à- j
&àè k
&à_ l
&àç ,
&&à n
&&& o
&&é p
&&" a
&&' r
&&( s
&&- t
&&è u
&&_ v
&&ç z
&éà x
&é& y
&éé w
&é" ¨
&é' µ
&é( £
&é- 
&éè

or alternative, is it a same problème is i used keyboard port PS2 instead of USB (+adapter ps2 to USB)?

this is for exemple my keyboard

http://hpics.li/edfb1c4

If you can make a hex file with whatever compiler, Teensy has that hex file loader utility.

So the reason I can't get Teensyduino to install to 1.6.9 is incompatibility? I tried to get the newest and the d/l hangs.

Maybe the map you need to change is on the PC, how it interprets keyboard input. Before you run your Leonardo sketch can you change your PC's keyboard setting to US then change back after?

keokod:
I used old IDE arduino, because a new version arduino (1.06) il not compatible.
I used teensdinio 1.29
http://hpics.li/c23c4f9

I understand from your picture that you use Arduino IDE version 1.06 (which is pretty old - 2012 or 2013 I think) but it may work even if Teensy LC is much newer.*

But what I also see from your picture: your keyboard layout setting is "US English".
Please, please, please, please, please try to switch to French! :slight_smile:

Menu: Outils / Keyboard Layout: French


*)
From the Teensy website:

Teensyduino 1.29 supports Arduino versions 1.0.6 and 1.6.5-r5 and 1.6.7 and 1.6.8 and 1.6.9.


GoForSmoke:
So the reason I can't get Teensyduino to install to 1.6.9 is incompatibility? I tried to get the newest and the d/l hangs.

I am always pretty chary in switching to a new(er) Arduino IDE versions. There have been so many buggy versions in the past... :slight_smile:
I think 1.6.5-r5 is pretty stable.
And I have always more than one versions in parallel on my computer - I use the zip file variants - so no installation is required.

Now i load arduino 1.6.9 is not erreur the same 1.6.11.

I try config système window7 french keyboard this is à picture

http://hpics.li/179f3c1

is in french but not key "<" is here ???

my keybard is microsft 4000

I think i try ide arduino and teensy with ubuntu, i wish the setup teensyduino is not difficult ...

in the new version HID.cpp is not présente.
But now we have

//C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy\keylayouts.h
keylaout.h

I read this:

#ifndef KEYLAYOUTS_H__
#define KEYLAYOUTS_H__

#include <stdint.h>
#include <avr/pgmspace.h>

#ifdef __cplusplus
extern "C"{
#endif

//#define LAYOUT_US_ENGLISH
//#define LAYOUT_CANADIAN_FRENCH
//#define LAYOUT_CANADIAN_MULTILINGUAL
//#define LAYOUT_DANISH
//#define LAYOUT_FINNISH
//#define LAYOUT_FRENCH
//#define LAYOUT_FRENCH_BELGIAN
//#define LAYOUT_FRENCH_SWISS
//#define LAYOUT_GERMAN
//#define LAYOUT_GERMAN_MAC
//#define LAYOUT_GERMAN_SWISS
//#define LAYOUT_ICELANDIC
//#define LAYOUT_IRISH
//#define LAYOUT_ITALIAN
//#define LAYOUT_NORWEGIAN
//#define LAYOUT_PORTUGUESE
//#define LAYOUT_PORTUGUESE_BRAZILIAN
//#define LAYOUT_SPANISH
//#define LAYOUT_SPANISH_LATIN_AMERICA
//#define LAYOUT_SWEDISH
//#define LAYOUT_TURKISH
//#define LAYOUT_UNITED_KINGDOM	
//#define LAYOUT_US_INTERNATIONAL

how i use it for activate friench layout ?

in folder teensy3 we have this

# set your MCU type here, or make command line `make MCU=MK20DX256`
MCU=MK20DX256

# make it lower case
LOWER_MCU := $(subst A,a,$(subst B,b,$(subst C,c,$(subst D,d,$(subst E,e,$(subst F,f,$(subst G,g,$(subst H,h,$(subst I,i,$(subst J,j,$(subst K,k,$(subst L,l,$(subst M,m,$(subst N,n,$(subst O,o,$(subst P,p,$(subst Q,q,$(subst R,r,$(subst S,s,$(subst T,t,$(subst U,u,$(subst V,v,$(subst W,w,$(subst X,x,$(subst Y,y,$(subst Z,z,$(MCU)))))))))))))))))))))))))))
MCU_LD = $(LOWER_MCU).ld

# The name of your project (used to name the compiled .hex file)
TARGET = main

# Those that specify a NO_ARDUINO environment variable will
# be able to use this Makefile with no Arduino dependency.
# Please note that if ARDUINOPATH was set, it will override
# the NO_ARDUINO behaviour.
ifndef NO_ARDUINO
# Path to your arduino installation
ARDUINOPATH ?= ../../../../..
#ARDUINOPATH ?= ../../../..
endif

# configurable options
OPTIONS = -DF_CPU=48000000 -DUSB_SERIAL -DLAYOUT_ENGLISH_US -DUSING_MAKEFILE

if i buy teensy 3 i think we must change layout_french ....

How to activate French keyboard layout in Arduino IDE with teensyduino add-on:

kbd_layout_fra.jpg

OH I'm very NOOOB !!

I no visible option keyboard langage in IDE arduino

now I have this <

Hel!
"
#
$
%

(
+
,
-
.
/
0
1
2
3
4
5
6
7
8
9
:
;
<
=
>
?
@
A
B
C
D
E
F
G
H
I
J
K
L
M

P
S
T
U
V
W
Y
Z]
^
_
`
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
{
|
}
~

thank's for HELP me and be patient.
I can continue may keyboard , tank you again

Oh yeah! :grin: :grin:

I wish you success with your project!

uxomm:
I think 1.6.5-r5 is pretty stable.
And I have always more than one versions in parallel on my computer - I use the zip file variants - so no installation is required.

We do the same and I haven't installed teensyduino in a good while now.

NI$HANT informed me that the Atmel studio has fewer quirks, I am tempted but can't share as much here.

I was wondering if you open a terminal emulator to capture the keystrokes, you might find emulator settings to avoid changing system settings.

it's too longer , but i test one one key for not have a error

this is a preview my keyboard left cut metal :cold_sweat: , i must kill 2 mécanique keyboard