Teensey as usb keyboard

Status
Not open for further replies.

Lucas

New member
Hello there,

recently I bought a new Teensey 3.6. I need it to work like a usb keyboard for my project. Therefore I tried to follow the steps on this website: https://www.pjrc.com/teensy/usb_keyboard.html , but the function usb_keyboard_press(key, modifier) doesn't work for me.

Here is the code I tried to write:

#include <print.h>
#include <usb_keyboard.h>

//int keyboard_keys[6];

const int buttonPin = 1;
const int buttonPin2 = 2;
const int buttonPin3 = 3;
const int buttonPin4 = 4;
const int buttonPin5 = 5;
const int buttonPin6 = 6;

boolean wasON = false;
int buttonState = 0;
int buttonState2 = 0;
int buttonState3 = 0;
int buttonState4 = 0;
int buttonState5 = 0;
int buttonState6 = 0;

void setup() {

pinMode(buttonPin, INPUT_PULLUP);
pinMode(buttonPin2, INPUT_PULLUP);
pinMode(buttonPin3, INPUT_PULLUP);
pinMode(buttonPin4, INPUT_PULLUP);
pinMode(buttonPin5, INPUT_PULLUP);
pinMode(buttonPin6, INPUT_PULLUP);

/* keyboard_keys[0] = 0;
keyboard_keys[1] = 0;
keyboard_keys[2] = 0;
keyboard_keys[3] = 0;
keyboard_keys[4] = 0;
keyboard_keys[5] = 0;
*/

}

void loop() {

buttonState = digitalRead(buttonPin);
buttonState2 = digitalRead(buttonPin2);
buttonState3 = digitalRead(buttonPin3);
buttonState4 = digitalRead(buttonPin4);
buttonState5 = digitalRead(buttonPin5);
buttonState6 = digitalRead(buttonPin6);

if (buttonState == LOW) {
usb_keyboard_press(KEY_A, KEY_SHIFT);
}
}

Thanks for your help!
 
That's for the oldest Teensy boards only.

For Teensy 3.6, use Arduino with Teensyduino. After running the installer, select Teensy 3.6 in Arduino's Tools > Boards menu. Then click File > Examples > Teensy > USB_Keyboard > Buttons to get started.

Before uploading, you also need to select Keyboard from Tools > USB Type, but you'll find that mentioned in the example's comments, and if you leave the default to Serial the error message should tell you about this too.
 
Status
Not open for further replies.
Back
Top