arduino leonardo keystrokes [solved]

Hello everyone,

I'm making a book, and I put a switch on each page that outputs a LOW to the Arduino when it's open and a HIGH when it's closed. There's a webcomic that I made ( — not quite cross-browser compatible yet so it might look wonky to some of you), and I'm trying to implement some keystrokes that navigate to a different webcomic panel when a new page is opened.

I got the page-turning algorithm down fine, but there seems to be a problem with the keystrokes. Only the first page/panel works. When I turn the pages, it always prints the correct page to the console, but the keystrokes simply do not work.

Here is my code for page 1, for example (I only have three pages wired/coded so far. Pages 2 and 3 follow more or less the same logic). I also put in the variables I'm using:

// assign pins for pages 1, 2, and 3
int page1 = 8;
int page2 = 9;
int page3 = 10;

// variable that changes whenever user turns to a specific page
int currentPage = 0;

// char variables created for tab and return commands
char tabKey = KEY_TAB;
char returnKey = KEY_RETURN;

// if only page 1 is low, and the current page isn't already 1:
  if(pageState1 == 0 && pageState2 != 0 && pageState3 != 0 && currentPage != 1) {
    Serial.print("state of page 1:");
    // if the user is just opening the book now
    if(currentPage == 0) {
      Serial.println("about to hit tab once");
      Serial.println("about to hit return");;
    // if the user was on page 2 previously
    if(currentPage == 2) {
      Serial.println("about to hit tab 7x");
      Serial.println("about to hit return");;
    //if the user was on page 3 previously:
    if(currentPage == 3) {
      Serial.println("about to hit tab 6x");
      Serial.println("about to hit return");;
    // set the current page to page 1
    currentPage = 1;

Anybody know why it's not working? Thank you!

Never mind, I figured out my problem! I should have been using keyboard.print instead of :slight_smile: