Arduino library : usb_keyboard.h

Hello, I downloaded the source files for the keyboard function on the website, this I have imported as a library in Arudino, but if it is to use, it is not Orange deposited, and the commands even if I want to export the program, it gives me a lot of errors, what's wrong?

I want the tennsy connect on a breadboard with four buttons.

Apology for the writing way, it is Google Translate.
Thx4Help.

Code:
#include <usb_keyboard.h>
#include <Bounce.h>



Bounce button0 = Bounce(0, 10);

void setup()
{
  pinMode(0, INPUT_PULLUP);
}

void loop()
{
  button0.update();
  if (button0.fallingEdge())
  {
      usb_Keyboard_press(KEY_F5, KEY_ALT);   
  }
  
}
Unbenannt2.jpg
Unbenannt.PNG
 
Last edited:
No, this is not the way. You do *not* include usb_keyboard.h.

In Arduino's Tools > USB Type menu, you select a type with Keyboard. No #include is used.

See File > Examples > Teensy > USB_Keyboard > Buttons for an example with 10 buttons. It should be very close to your needs. Just delete the 6 buttons you do not use.
 
But why dosen't work command like : usb_keyboard_press(); ?
Because i want to make keyboard shortcut like : ALT F4;
And on the webseite is : Unbenannt.PNG
 
Last edited:
Ausnahmsweise auf Deutsch: Du brauchst nichts zu installieren, falls du es schon getan hast, lösche deine manuell installierte Kopie, oder früher oder später geht was schief.. Stelle "Usb-Type" auf Keyboard, starte das Beispiel und alles ist gut... :)

Sorry for using German :)
 
As Paul said, no need to download anything. The example on the website is somewhat very old. The compiler includes the library automatically if you compile your project with the Tools > USB Type menu, selecting a keyboard option.

Then, usb_keyboard_press() will compile and work.

If you have problems in understanding English (you wrote that you used Google Translate), let us know your language and we'll make an effort to explain. From my side, French and German is available.
 
Thank you, i speak German :D

Ich habe es so versucht, wie Sie es beschreiben haben, aber es funktioniert immer noch nicht!
Code:
#include <Bounce.h>


Bounce button0 = Bounce(0, 10);
Bounce button1 = Bounce(1, 10);  // 10 = 10 ms debounce time
Bounce button2 = Bounce(2, 10);  // which is appropriate for
Bounce button3 = Bounce(3, 10);  // most mechanical pushbuttons

void setup() 
{

  pinMode(0, INPUT_PULLUP);
  pinMode(1, INPUT_PULLUP);
  pinMode(2, INPUT_PULLUP);
  pinMode(3, INPUT_PULLUP);
}

void loop() 
{
  button0.update();
  button1.update();
  button2.update();
  button3.update();


  if (button0.fallingEdge()) 
  {
    usb_keyboard_press(KEY_F4, KEY_ALT);
  }
  if (button1.fallingEdge()) 
  {
    Keyboard.println("B1 press");
  }
  if (button2.fallingEdge()) 
  {
    Keyboard.println("B2 press");
  }
  if (button3.fallingEdge()) 
  {
    Keyboard.println("B3 press");
  }

}

Und der Fehler :
Arduino: 1.6.8 (Windows 7), TD: 1.28, Board: "Teensy 2.0, Keyboard + Mouse + Joystick, 16 MHz, German Swiss"

Build options changed, rebuilding all
Buttons: In function 'void loop()':
Buttons:30: error: 'KEY_ALT' was not declared in this scope
usb_keyboard_press(KEY_F4, KEY_ALT);

^

Buttons:30: error: 'usb_keyboard_press' was not declared in this scope
usb_keyboard_press(KEY_F4, KEY_ALT);

^

'KEY_ALT' was not declared in this scope

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
 
German: So, jetzt nach Studium des Handbuches sind wir schlauer. Das von "Elektroniker" angeführte Code-Beispiel kann nicht in der aktuellen Teenyduino-Umgebung funktionieren. Ich weiss nicht, wo es herkommt (Edit: von der veralteten Webseite). Unterstehend ein Code-Beispiel, dass ich selbst geprüft habe und was funktioniert. Un nächstes Mal: RTFM!!! (=Read The F...ing Manual =Lies das verdammte Handbuch)

English: Now, after studying the reference, we are smarter. "Elektroniker's" code example can not work in the actual Teensyduino environment. I've no clue from where he took it (Edit: From the totally outdated website). Below a code example which I tested myself and which works. And next time: RTFM!!!

Code:
#include <Bounce.h>


Bounce button0 = Bounce(0, 10);
Bounce button1 = Bounce(1, 10);  // 10 = 10 ms debounce time
Bounce button2 = Bounce(2, 10);  // which is appropriate for
Bounce button3 = Bounce(3, 10);  // most mechanical pushbuttons

void setup() 
{

  pinMode(0, INPUT_PULLUP);
  pinMode(1, INPUT_PULLUP);
  pinMode(2, INPUT_PULLUP);
  pinMode(3, INPUT_PULLUP);
}

void loop() 
{
  button0.update();
  button1.update();
  button2.update();
  button3.update();


  if (button0.fallingEdge()) 
  {
    //Tasten druecken und uebermitteln:
    Keyboard.set_modifier(MODIFIERKEY_ALT);
    Keyboard.set_key1(KEY_F4);
    Keyboard.send_now();
    //Kurz warten:
    delay(5);
    //Tasten loslassen und uebermitteln:
    Keyboard.set_modifier(0);
    Keyboard.set_key1(0);    
    Keyboard.send_now();
  }
  if (button1.fallingEdge()) 
  {
    Keyboard.println("B1 press");
  }
  if (button2.fallingEdge()) 
  {
    Keyboard.println("B2 press");
  }
  if (button3.fallingEdge()) 
  {
    Keyboard.println("B3 press");
  }

}
 
Last edited:
Danke für die gute Antwort, ich kann es aber leider erst am Mittwoch austesten. Und ich werde das nächste mal bestimmt das Handbuch lesen :)
 
Back
Top