Keyboard Library not working when code in tabs


I am trying to use Keyboard.h library for a project using Arduino DUE to press certain characters on the keyboard.

When I have my code in the main tab I don't have any problem at all but when I move certain pieces to other tabs everything works with the exception of all the bits of code related to Keyboard.h.

In the tabs I moved certain methods I have created and I recall them at the beginning of the main tab with "void methodname();", from what I understood in previous project I've faced this should make the compiler to find all the bits of code in the appropriate order.

Thank you very much for your help,

My best,


What does “not work” mean?
Does not compile (show us your error) or does not run (tell us what you expected and what you actually saw)?
Show your code!

The code is enormous and I didn’t want to drive you crazy :slight_smile:

Here is the extract that I think is relevant:


#include <Keyboard.h>

There are no other references of Keyboard library in the main tab


void encoder0() {
static int8_t c,val;

   if( val=read_rotary() ) {
      c +=val;
      if ( prevNextCode==0x0b) {
         Serial.println("RE 1 CCW);
         Keyboard.begin();;;; ('r');
      if ( prevNextCode==0x07) {
         Serial.println("RE 1 CW);
         Keyboard.begin();;;; ('e');
      previous_event = event;
      display_level("RGB CHANNEL", 0, "Highlights Input", 0);

This is a modification of this: basically, I have some rotary encoder and I need, for each step, to make arduino press that combination of modifiers and characters.

If I move this method to TAB 1 (instead of having it in the main tab) it will compile BUT while the serial would still print perfectly at each step, none of the Keyboard input will be recognized by the computer.

I hope I have explained it properly!

Many thanks!


dd you include "Keyboard.h" in the file using it?

I didn't know I had to...

it works perfectly now!


I have tried to move all my "encoder" methods in the new tab and weirdly, if I move all of them, it stop working again.
If I leave even just one method in the main tab then all of them (also the one in TAB 1) work perfectly...