Leonardo as Keyboard Inconsistent Capitalization

Working with the KeyboardMessage example. Using all caps in the default message, I get various results, e.g.:

YOu PrESSeD tHE bUTTON 2 TIMES.

Oddly, TIMES is consintently delivered in all caps, even though I left it all lower case in the sketch.

If I look at the examples in my IDE, there is no example called KeyboardMessage. I suggest that you post your code here and tell us which board and operating system you are using.

Arduino Leonardo, Ubuntu 22.04, IDE 2.3.2
From https://docs.arduino.cc/built-in-examples/usb/KeyboardMessage/ :

Keyboard Message test
For the Arduino Leonardo and Micro
Sends a text string when a button is pressed
The circuit:
- pushbutton attached from pin 4 to +5V
- 10 kilohm resistor attached from pin 4 to ground

created 24 Oct 2011
modified 27 Mar 2012
by Tom Igoe
modified 11 Nov 2013
by Ocott Fitzgerald

This example code is in the public domain.
https://www.arduino.cc/en/Tutorial/BuiltInExamples/KeyboardMessage
*/
#include "Keyboard.h"

const int buttonPin = 4;     // input pin for pushbutton
int previousButtonState = HIGH;     //for checkint the state of a pushButton
int counter = 0;     //button push counter

void setup() {
// make the pushButton pin an input
pinMode(buttonPin, INPUT);
// initialize control over the keyboard:
Keyboard.begin();

}

void loop() {
// read the pushbutton:
int buttonState = digitalRead(buttonPin);
// if thu button state has changed,
if ((buttonState != previousButtonState)
// and it's currently pressed:
&& (buttonState == HIGH)) {
// increment the button counter
counter++;
// type out a message
Keyboard.print("YOU PRESSED THE BUTTON ");
Keyboard.print(counter);
Keyboard.println(" times.");
}
// save the current button state for comparison next time:
previousButtonState = buttonState;
+

In playing around, I find that even using Keyboard.write produces anomalous results.

Keyboard.write(65);
Keyboard.write(97);

produces: 'aa'

And, if I do:

Keyboard.press(KEY_LEFT_SHIFT);
Keyboard.press('a');
Keyboard.releaseAll();

I get: 'a'

But, if I do:

Keyboard.press(KEY_RIGHT_SHIFT);
Keyboard.press('a');
Keyboard.releaseAll();

I get: 'A'

Thanks for the code. And I did actually find it on my system, sorry.

I unfortunately can not reproduce the issue; running Antix Linux 32-bit. I used geany to catch the output

YOU PRESSED THE BUTTON 2 times.
YOU PRESSED THE BUTTON 3 times.
YOU PRESSED THE BUTTON 4 times.
YOU PRESSED THE BUTTON 5 times.
YOU PRESSED THE BUTTON 6 times.
YOU PRESSED THE BUTTON 7 times.
YOU PRESSED THE BUTTON 8 times.
YOU PRESSED THE BUTTON 9 times.
YOU PRESSED THE BUTTON 10 times.
YOU PRESSED THE BUTTON 11 times.
YOU PRESSED THE BUTTON 12 times.

I am coming to the conclusion that this is, at least partly, a hardware problem. Although I have no clue what kind of hardware problem it might be, given that even sending the ascii code for A produces anomalous results.

There is one more thing (and I doubt it's the cause of your problem); I don't think that println is supposed to work as expected (though it did on my system). println send a "\r\n" while the keyboard is supposed to send a keycode for RETURN (0xB0).

PC? Maybe keyboard settings? No idea which ones though.

In any event, thank you for responding.

In the end, for the application I am working on (keyboard output from morse key input) , it won't matter whether an A or an a appears on the screen.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.