Pro trinket keyboard modifiers

Our weekly LIVE video chat. Every Wednesday at 8pm ET!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
Hhgarris
 
Posts: 3
Joined: Thu Aug 20, 2015 1:33 pm

Pro trinket keyboard modifiers

Post by Hhgarris »

i have TONs of chrombooks to add to the enterprise. i bought a pro trinket and received it yesterday but i am having problems getting the key modifiers to work. i need to press control-alt-e to start the enrollment process but i get nothing. Please look at my code and fix my stupid mistake.

Thanks

start code
****************************************

Code: Select all

/*
ProTrinketKeyboard example
For Pro Trinket (ATmega328 based Trinket) by Adafruit Industries
Please use library TrinketKeyboard for the ATtiny85 based Trinket
Version 1.0  2015-01-01 Initial Version derived from TrinketKeyBoardExample  Mike Barela
*/

#include <ProTrinketKeyboard.h>  // Ensure the library is installed

// Switches are connected from ground to these defined pins
const int PIN_BUTTON_CAPITAL_A = 11;
const int PIN_BUTTON_STRING    = 12;

void setup()
{
  // Declare button pins as inputs
  pinMode(PIN_BUTTON_CAPITAL_A, INPUT_PULLUP);
  pinMode(PIN_BUTTON_STRING,    INPUT_PULLUP);

  // setting input pins to high means turning on internal pull-up resistors
  digitalWrite(PIN_BUTTON_CAPITAL_A, HIGH);
  digitalWrite(PIN_BUTTON_STRING,    HIGH);
  // remember, the buttons are active-low, they read LOW when they are not pressed

  // start USB stuff
  TrinketKeyboard.begin();
}

void loop()
{
  TrinketKeyboard.poll();
  // the poll function must be called at least once every 10 ms
  // or cause a keystroke
  // if it is not, then the computer may think that the device
  // has stopped working, and give errors

  
  if (digitalRead(PIN_BUTTON_CAPITAL_A) == LOW)
  {
     //this is the section i cant get to work THANKS
     
     TrinketKeyboard.pressKey(KEYCODE_MOD_LEFT_CONTROL, KEYCODE_MOD_RIGHT_ALT, KEYCODE_E);
     TrinketKeyboard.pressKey(0, 0);
     delay(1000);  
  }

  
  if (digitalRead(PIN_BUTTON_STRING) == LOW)
  {
    // type out a string using the Print class
    TrinketKeyboard.println("[email protected]");
    delay(2000);
    TrinketKeyboard.println("password");
     }
}
****************************
end code

Thanks

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: Pro trinket keyboard modifiers

Post by adafruit_support_rick »

You need to OR the modifiers together. The modifiers are only the first argument to pressKey

Code: Select all

  if (digitalRead(PIN_BUTTON_CAPITAL_A) == LOW)
  {
     //this is the section i cant get to work THANKS
     
     TrinketKeyboard.pressKey(KEYCODE_MOD_LEFT_CONTROL | KEYCODE_MOD_RIGHT_ALT,  KEYCODE_E);  //OR modifiers together into first argument
     TrinketKeyboard.pressKey(0, 0);
     delay(1000);  
  }

User avatar
Hhgarris
 
Posts: 3
Joined: Thu Aug 20, 2015 1:33 pm

Re: Pro trinket keyboard modifiers

Post by Hhgarris »

thanks i will give it a try

User avatar
Hhgarris
 
Posts: 3
Joined: Thu Aug 20, 2015 1:33 pm

Re: Pro trinket keyboard modifiers

Post by Hhgarris »

OK now i need to know how to push a single key like say the TAB key. i thought it would be like this "TrinketKeyboard.pressKey(KEYCODE_TAB);" but i'm getting an error.

I guess the better question would be is there a list of key combinations somewhere? i have opened the ProTrinketKeyboard.h and looked through it but really don't know enough to even begin to know what im looking at.

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: Pro trinket keyboard modifiers

Post by adafruit_support_rick »

You still need the modifier argument. Use 0:

Code: Select all

TrinketKeyboard.pressKey(0, KEYCODE_TAB);

User avatar
rausimous
 
Posts: 1
Joined: Fri Jul 08, 2016 4:34 pm

Re: Pro trinket keyboard modifiers

Post by rausimous »

thank you verry mutch

for the post

i was looking for 5h for this (by trial and eror)

there is noting in the discription about what to do if you dont want a modifier key

so to every one is you dont want a modifier key just type

TrinketKeyboard.pressKey(0,KEYCODE_"the key");

Locked
Please be positive and constructive with your questions and comments.

Return to “Ask an Engineer! VIDEO CHAT (closed)”