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

Thread: Accessing Keyboard.press from a .cpp file

Hybrid View

  1. #1

    Accessing Keyboard.press from a .cpp file

    This is more an Arduino IDE question than a Teensy question, but I'm hoping you guys know the answer. I'm trying to split my project up so it's more manageable, so I've set it up similarly to this:

    Code:
    main/
      src/
        some-class.h
        some-class.cpp
      main.ino
    If I call Keyboard.press from main.ino it's fine, but if I call it from some-class.cpp I get:

    Code:
    error: 'Keyboard' was not declared in this scope
    To make a USB Keyboard, use the Tools > USB Type menu
         Keyboard.press(m_keycode);
    This is a Teensy 3.6 and the USB Type is set as "Serial + Keyboard + Mouse + Joystick". Is there something I need to #include to get Keyboard to work from a .cpp file, or is there some kind of extern declaration that I need?

  2. #2
    Code:
    #include <usb_keyboard.h>
    Seems to fix it.

Posting Permissions

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