Teensy 2.0 not sending <CRTL> keystroke

Status
Not open for further replies.

reid21

Member
Can't seem to get Teensy 2.0 to send <CTRL> Keystroke using keyboard.press, keyboard.write or keyboard.print. Using Arduino. I have verified the Teensy 2.0 board with blink and also have sent text using keyboard.print.
 
Last edited:
Can't seem to get Teensy 2.0 to send <CTRL> Keystroke using keyboard.press, keyboard.write or keyboard.print. Using Arduino. I have verified the Teensy 2.0 board with blink and also have sent text using keyboard.print.

Please post the code using Keyboard.press(), and then I'll look into this.
 
If I have notepad open and active all I get is "1" or "2". What it should do is switch to another computer as I have the Teensy pluged into a KVM switch. With a normal Keyboard plug in the key sequence "<Left CTRL> <Left CTRL> 1" switches to computer 1...

I have had keyboard.start in the setup but it does not seem to mater.

int SWPin =0;
int Comp_Status = 1;
char CtrlKey = KEY_LEFT_CTRL
void setup()
{
Serial.begin(9600);
pinMode(SWPin,INPUT_PULLUP);
}


void loop(){
if (digitalRead(SWPin)== LOW)
{
if (Comp_Status == 1)
{
Keyboard.begin();
Keyboard.press(CtrlKey);
delay (100);
Keyboard.release(CtrlKey);
delay (200);
Keyboard.press(CtrlKey);
delay (100);
Keyboard.release(CtrlKey);
delay (100);
Keyboard.print ("1");
Comp_Status = 2;
delay (500);
Keyboard.end();
}
else
{
Keyboard.begin();
Keyboard.press(CtrlKey);
delay (100);
Keyboard.release(CtrlKey);
delay (200);
Keyboard.press(CtrlKey);
delay (100);
Keyboard.release(CtrlKey);
delay (200);
Keyboard.print ("2");
Comp_Status = 1;
delay (500);
Keyboard.end();
}
}
}
 
I also tried the sample code from the Arduino to send a "<CTRL> N" to start a new doc. I changed the pin to 0 for my app.

// use this option for OSX:
char ctrlKey = KEY_LEFT_GUI;
// use this option for Windows and Linux:
// char ctrlKey = KEY_LEFT_CTRL;

void setup() {
// make pin 2 an input and turn on the
// pullup resistor so it goes high unless
// connected to ground:
pinMode(2, INPUT_PULLUP);
// initialize control over the keyboard:
Keyboard.begin();
}

void loop() {
while (digitalRead(2) == HIGH) {
// do nothing until pin 2 goes low
delay(500);
}
delay(1000);
// new document:
Keyboard.press(ctrlKey);
Keyboard.press('n');
delay(100);
Keyboard.releaseAll();
// wait for new window to open:
delay(1000);
}
 
Last edited:
I tried a very simple CapsLocker and believed, that its not working, but when I also send charachter (after the KEY_CAPS_LOCK) so tis key came in uppercase.
I also could not see, that the CAP_LOCK LED on trhe keyboard goes on.

Then I started a virtual maschine (my host is an mac-book-air) and in windows erverything worked as expected.

With other word, when MAC detects a new keyboard (in this case, my teensy 2.0) the keyboards acts completly autonom, CTRL on one Keyboard and D on the other are not compined. Only when the keys are pressed on the same keyboard. Windows is here much more primitiv.

I tred it also on a ubuntu 10.04 virtual mashine, also ther my Capslocker wotks. Just Mac seems to be a little bit smarter.
What OS are you running ?
 
Does anyone know of a program that shows all keycodes the PC is receiving? Seems like I've seen such a thing before... maybe it was a Mac utility?

I suppose I could write something, but it'd a time-saver if anyone could point to an already-written program.

With something to display all the keycodes as the operating system makes them available to the user space programs, I'll look into this control key issue. I can test on Mac, Linux and Windows. But I probably can't do anything about a KVM switch.
 
I believe that if you can get the "<CTRL> N" to start a new document from the Ardunio example working then the code for the KVM switch will work.

Reid
 
I think I am experiencing issues similar to the above. I am trying to send the caps lock keystroke to a Mac in my void setup after a 3 second delay. This seems to work fine on a windows box, but on the mac it will not illuminate the caps lock LED or turn caps lock on. Has anyone had issues with this or know of a solution. Maybe there is a change that can be made in the library to support Mac?
 
OK, so #PaulStoffregen I am sure you already know, but using the Serial.read() to map the read keys to an integer and then using Serial.write() will allow you to see what the raw keycode is. Judging by the number of posts you have id say my previous statement is mute point. But I have figured out the way to remap a keystroke from the keyboard library to another raw key code.

#define KEY_CAPS_LOCK byte(0x39)

Although after looking up the raw key codes they are exactly the same. I am pretty disappointed to find that the caps lock will not activate on the Mac from the Teensy's instruction to do so. What are my options at this point??
 
but on the mac it will not illuminate the caps lock LED or turn caps lock on.

Perhaps you're really expecting your mac to transmit new LED info to all connected keyboards when any of them changes? I believe Windows does that, but does Mac do it also? (really, I'm asking... I do not know)

As a simple test, please try plugging 2 real USB keyboards (not Teensy) into your mac. When you press the caps lock on one keyboard, does the LED change on both or only on that one keyboard?

If Apple is managing the caps lock as a separate setting on each individual keyboard, I hope you can see how Teensy can't control that process!
 
If you actually do this 2 keyboard test on your Mac, please report the results here. Whatever the outcome, it'll probably help others who are seeing differences between Windows and Mac systems.
 
OK, so I was a bit tired last night and wasn't thinking logically about how the mac would control other keyboards. Come to find out during boot and a quick trip to the BIOS on a dell I have here, I was still able to turn the caps lock on and off with the teensy. However, after testing the Mac with an Apple keyboard, a rollup keyboard, and a logitech keyboard; I was able to get the information we were looking for. All keyboard keys are independant period. Case study:

MBP A1278
Logitech Keyboard
Apple Keyboard
iHome Keyboard

After booting with 2 of the three keyboards plugged in I opened textEdit and was surprised to find that when hitting Caps Lock on the Apple keyboard I was able to type all caps. When I typed on the other two keyboards it still remained lowercase. When I hit the Caps Lock on another keyboard there were no LED status changes on other keyboards, but I was able to type uppercase on the two keyboards I had pressed Caps Lock on. Third and final Keyboard I pressed Caps Lock and the exact same thing has happened again. I repeated the steps in reverse and found that each keyboard was completely independent.
 
My next question would be, IS THERE a way to detect the current state of another keyboard? Or detect if the system sees a Caps Lock or even change of event.
 
All keyboard keys are independant period.

Yup. Case closed, right?

Teensy is working correctly but with Macs you can't observe one keyboard's caplock state by looking at another keyboard. Or if you're trying to play tricks where one keyboard causes another to change to caplock, like you can do with Windows, you just can't do that with Macs because Apple wrote better software.
 
Status
Not open for further replies.
Back
Top