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

Thread: Arduino library : usb_keyboard.h

  1. #1

    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);   
      }
      
    }
    Click image for larger version. 

Name:	Unbenannt2.jpg 
Views:	57 
Size:	50.3 KB 
ID:	7279
    Name:  Unbenannt.PNG
Views: 208
Size:  1.5 KB
    Last edited by Elektroniker; 06-02-2016 at 02:52 PM.

  2. #2
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    16,263
    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.

  3. #3
    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 : Click image for larger version. 

Name:	Unbenannt.PNG 
Views:	40 
Size:	8.4 KB 
ID:	7282
    Last edited by Elektroniker; 06-02-2016 at 02:53 PM.

  4. #4
    and what are the downloads: Click image for larger version. 

Name:	blabla.PNG 
Views:	95 
Size:	6.9 KB 
ID:	7283

  5. #5
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    4,347
    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

  6. #6
    Senior Member+ Theremingenieur's Avatar
    Join Date
    Feb 2014
    Location
    Colmar, France
    Posts
    1,153
    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.

  7. #7
    Thank you, i speak German

    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.

  8. #8
    Senior Member+ Theremingenieur's Avatar
    Join Date
    Feb 2014
    Location
    Colmar, France
    Posts
    1,153
    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 by Theremingenieur; 06-03-2016 at 05:10 PM.

  9. #9
    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

Tags for this Thread

Posting Permissions

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