Go Down

Topic: Odd leonardo keyboard problem (Read 925 times) previous topic - next topic

DFTBA

Whenever I use my Leonardo as a keyboard, it has issues with the shift key. Mainly, this is my code.

Code: [Select]
void setup()
{
  Keyboard.begin();
}
void loop()
{
  Keyboard.press(0x64);
  delay(100);
  Keyboard.release(0x64);
}


It should type a "d" over and over. However, it types "D" over and over. Also, even when I unplug the Arduino, the key is still pressed. Can anyone help me?

Grumpy_Mike

Quote
even when I unplug the Arduino, the key is still pressed. Can anyone help me?

That is because you have to unplug it in the time between the release and the press, which is very very short. Insert a delay just before the end of the loop.

DFTBA

Yes, but why is the shift key pressed at all? I didn't command that.

Grumpy_Mike

Quote
but why is the shift key pressed at all?

It isn't, you are sending 0x64 directly into the keyboard buffer. This is a lower case d, and that is what I get when I run your code.

If you get an uppercase D then there must be some modifier that your software is taking from your other keyboard.

This is the code I used:-
Code: [Select]
void setup()
{
  Keyboard.begin();
  digitalWrite(7,HIGH); // enable pullups on pin 7
  while(digitalRead(7) == HIGH) { } // do nothing until pin 7 is pulled low
}
void loop()
{
  Keyboard.press(0x64);
  delay(100);
  Keyboard.release(0x64);
    // delay(400);
}

The trigger in the setup is to prevent trouble downloading future sketches as advised in the release notes for the Leonardo.


James C4S

Capacitor Expert By Day, Enginerd by night.  ||  Personal Blog: www.baldengineer.com  || Electronics Tutorials for Beginners:  www.addohms.com

Grumpy_Mike

When I run your code I get lower case ds. Therefore there is nothing wrong with your code.

Your error lies not with your arduino but with the system you are feeding your arduino into.
Can you describe what you are doing. Operating system, other keyboards, application at the computer end.

Go Up