Keyboard Library not working when code in tabs

Hello,

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,

Alessandro

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:

MAIN TAB

#include <Keyboard.h>

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

TAB 1

void encoder0() {
static int8_t c,val;

   if( val=read_rotary() ) {
      c +=val;
      
      if ( prevNextCode==0x0b) {
         ccw_counting(0);
         Serial.println("RE 1 CCW);
         Keyboard.begin();
         Keyboard.press(ctrlkey);
         Keyboard.press(altkey);
         Keyboard.press(commandkey);
         Keyboard.press ('r');
         Keyboard.releaseAll();
         Keyboard.end();               
      }
      if ( prevNextCode==0x07) {
         cw_counting(0);
         Serial.println("RE 1 CW);
         Keyboard.begin();
         Keyboard.press(ctrlkey);
         Keyboard.press(altkey);
         Keyboard.press(commandkey);
         Keyboard.press ('e');
         Keyboard.releaseAll();       
         Keyboard.end();
      }    
      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!

Alessandro

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

:smiley:
I didn't know I had to...

Thanks,
it works perfectly now!

Actually...

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